in reply to Re^3: Mr. Ternary is greater than Mrs. If Else
in thread Mr. Ternary is greater than Mrs. If Else
perl -le 'use strict; my $foo = 1; $foo ? \&{print "foo"} : \&{ print +"bar"};' foo
Inside a ternary ?: the expressions are evaluated - and \& { } constructs a code ref
block which gets evaluated at runtime, to get at the name of the symbol table entry CODE slot from which a reference is taken.
<update>
For the bare \& { } try e.g.
perl -le 'use strict; my $foo = \&{ print "bar"}; $foo'
</update>
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Mr. Ternary is greater than Mrs. If Else
by blazar (Canon) on May 20, 2007 at 12:13 UTC |