in reply to Re: Program unsuspectingly dies with no reason why.
in thread Program unsuspectingly dies with no reason why. -FIXED!
Actually, &foo() is a call to the sub foo. To take a reference to the sub, use \&foo.
sub foo { print "foo: ", $_[0], "\n" } &foo( 'called with &' ); foo( 'called with no &' ); my $foo_ref = \&foo; $foo_ref->( 'called via reference' ); &$foo_ref( 'called via & and reference' ); __END__ foo: called with & foo: called with no & foo: called via reference foo: called via & and reference
The only special thing about &foo() vs. foo() is that the former will disable any prototypes the sub may have.
|
|---|