in reply to Re^2: Mr. Ternary is greater than Mrs. If Else
in thread Mr. Ternary is greater than Mrs. If Else
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).
Well, there's a subtle difference. When you write &{foo} -with no quotes within the curlies-, that's (almost) just as if you had written &foo. This is not specific of subs, but of quite about all kind of variables:
spock:~ [16:02:30]$ perl -wMstrict -le 'my $x=1; print ${x}' Ambiguous use of ${x} resolved to $x at -e line 1. 1 spock:~ [16:02:36]$ perl -wMstrict -le 'my $x=1; print ${"x"}' Can't use string ("x") as a SCALAR ref while "strict refs" in use at - +e line 1.
|
|---|