What pseudo-operators exist in Perl 5?

后端 未结 9 1515
孤城傲影
孤城傲影 2020-11-28 07:05

I am currently documenting all of Perl 5\'s operators (see the perlopref GitHub project) and I have decided to include Perl 5\'s pseudo-operators as well. To me, a pseudo-o

相关标签:
9条回答
  • 2020-11-28 07:29

    The Perl secret operators now have some reference (almost official, but they are "secret") documentation on CPAN: perlsecret

    0 讨论(0)
  • 2020-11-28 07:32

    Nice project, here are a few:

    scalar x!! $value    # conditional scalar include operator
    (list) x!! $value    # conditional list include operator
    'string' x/pattern/  # conditional include if pattern
    "@{[ list ]}"        # interpolate list expression operator
    "${\scalar}"         # interpolate scalar expression operator
    !! $scalar           # scalar -> boolean operator
    +0                   # cast to numeric operator
    .''                  # cast to string operator
    
    { ($value or next)->depends_on_value() }  # early bail out operator
    # aka using next/last/redo with bare blocks to avoid duplicate variable lookups
    # might be a stretch to call this an operator though...
    
    sub{\@_}->( list )   # list capture "operator", like [ list ] but with aliases
    
    0 讨论(0)
  • 2020-11-28 07:32

    The "goes to" and "is approached by" operators:

    $x = 10;
    say $x while $x --> 4;
    # prints 9 through 4
    
    $x = 10;
    say $x while 4 <-- $x;
    # prints 9 through 5
    

    They're not unique to Perl.

    0 讨论(0)
提交回复
热议问题