Corion is correct. If, for some reason, you don't want to define a sub that does this, you can use an anonymous sub the same way.
my $parameter = qq{param at declaration\n}; my $print_ref = sub { my ($p) = @_; sub { print $p } }->( $parameter ) +; $print_ref->(); $parameter = qq{param after declaration\n}; $print_ref->(); __END__ param at declaration param at declaration
I wouldn't recommend this for anything more complicated than a single line, however. I wouldn't want to read to the end of a block of code to find "->(...)" dangling off of it.
In reply to Re: How to get variable evaluation in anonymous subroutines declaration
by kyle
in thread How to get variable evaluation in anonymous subroutines declaration
by zorglups
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |