=head1 NAME Perl6::Overview::Operator - Operators =head1 DESCRIPTION =head2 Precedence terms 42 "eek" $x /abc/ (1+2) a(1) :by(2) .meth ./meth listop method postfix . .+ .? .* .+ .() .[] .{} .«» .= autoincrement ++ -- exponentiation ** symbolic unary ! + - ~ ? * ** +^ ~^ ?^ \ multiplicative * / % x xx +& +< +> ~& ~< ~> additive + - ~ +| +^ ~| ~^ junctive and (all) & junctive or (any) | ^ named unary rand sleep abs etc. nonchaining binary => but does cmp <=> .. ^.. ..^ ^..^ chaining binary != == < <= > >= ~~ !~ eq ne lt le gt ge =:= === tight and && tight or || ^^ // ternary ?? !! assignment = := ::= += -= **= xx= etc. list item separator , ¥ list op (rightward) <== [+] print push any all true not etc. pipe forward ==> loose and and loose or or xor err expr terminator ; {} as control block, statement modifiers =head2 Simple arithmetic operators 4 + 2 # 6, addition 4 - 2 # 2, substraction 4 * 2 # 8, multiplication 4 / 2 # 2, division 4 ** 2 # 16, exponentiation 4 % 2 # 0, modulo =head2 Bit operators Numeric Stringy Boolean --------------------------- +| ~| ?| # OR +& ~& ?& # AND +^ ~^ ?^ # XOR +^ ~^ ?^ # Negation (prefix unary) +< ~< # Shift left +> ~> # Shift right =head2 Unary context operators + # Num ~ # Str ? # Bool int # Int item # Item list # List hash # Hash pair # Pair =head2 Meta-operators @foo >>op $bar # hyper loop over left side $foo op<< @bar # hyper loop over right side @foo >>op<< @bar # hyper loop over both sides, parallel [+] @foo # reduce with specified infix op [+] 1, 2, 3 # 1 + 2 + 3 .= .? .* .+ # See oo =head2 Assignment operators $copy = $foo # assign $alias := $foo # bind, runtime $alias ::= $foo # bind, compile time $foo++ # postincrement $foo-- # postdecrement ++$foo # preincrement --$foo # predecrement $foo op= $bar # mutate ($foo = $foo op $bar), where op is any infix =head2 Comparison operators Num Str Generic ------------------- == eq # equality (value) != ne # negated equality (value) < lt # less than > gt # greater than <= le # less than or equal to >= ge # greater than or equal to <=> cmp # lt => -1, eq => 0, gt => 1 ~~ # smart match (see smartmatch) !~ # negated smart match =:= # equality (container) === # equality (value) =head2 Logic operators HighPrec LowPrec ----------------- && and # infix || or # infix ^^ xor # infix // err # infix (defined-or) ! not # prefix ? true # prefix ?? !! # ternary =head2 Quote-like operators Generalized Short Shorter ----------------------------- q:0 q:1 q '' q:2 qq "" q:to q:0:w qw <> q:2:w qww «» <<>> # XXX qww or qqw? :2:w correct? m // rx // =head2 Junctive operators $foo | $bar | $baz # any($foo, $bar, $baz) $foo & $bar & $baz # all($foo, $bar, $baz) $foo ^ $bar ^ $baz # one($foo, $bar, $baz) (no chaining op) # none($foo, $bar, $baz) =head2 Yada yada yada operators (terms) ... # fail "$?BLOCKNAME is not yet implemented" ??? # warn "$?BLOCKNAME is not yet implemented" !!! # die "$?BLOCKNAME is not yet implemented" =head2 Miscellaneous operators \$foo # capture $foo ~ $bar # string concat $foo x 3 # $foo ~ $foo ~ $foo $foo xx 3 # ($foo, $foo, $foo) @foo Y @bar Y @baz # zip(@foo, @bar, @baz) item ($foo, $bar) # [ $foo, $bar ] 1..5 # (1, 2, 3, 4, 5) "a".."g" # ; # statement separator =head2 See also .method # oo .=method # oo ./method # oo .() # sub .[] # data .{} # data .<> # data .<<>> # data $, @, %, &, :: # data k => $v # data :k($v) # data <==, ==> # sub ~~ # smartmatch =cut