The ampersand & marks the following { } construct as a code block; the backslash disambiguates that operation from binary '&' (the bitwise AND) and returns a reference for that code block.
It's not really a code block. \&{foo} is a reference to the subroutine with the name "foo". Similarly, \& { print "foo" } is a reference to the subroutine with the name that is returned by print, i. e. it's \&1 (unless print fails).
$ perl -lwe 'my $code = \&{print "foo"}' foo $ perl -lwe 'my $code = \&{print "foo"}; $code->()' foo Undefined subroutine &main::1 called at -e line 1.
(Note that $code is not called/dereferenced in the first one-liner, yet it prints foo.
In reply to Re^2: Mr. Ternary is greater than Mrs. If Else
by betterworld
in thread Mr. Ternary is greater than Mrs. If Else
by PerlPhi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |