in reply to calling a sub using a variable's value
In the first instance we're executing the subroutine returned by UNIVERSAL, and in the second instance we're creating a sub reference and then executing (the parens are necessary for syntactical disambiguation).use strict; sub foo { print "this is foo(@_)\n" } sub bar { print "this is bar(@_)\n" } __PACKAGE__->can($_)->('invoked via can()') for qw/ foo bar /; ( \&$_ )->('invoked without a temp var') for qw/ foo bar /; __output__ this is foo(invoked via can()) this is bar(invoked via can()) this is foo(invoked without a temp var) this is bar(invoked without a temp var)
_________
broquaint
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: calling a sub using a variable's value
by dragonchild (Archbishop) on Apr 23, 2004 at 19:21 UTC |