Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: strange code (de)referencing behavior

by kennethk (Monsignor)
on Feb 10, 2012 at 15:54 UTC ( #953060=note: print w/ replies, xml ) Need Help??


in reply to strange code (de)referencing behavior

If you modify your code to output the content of the incoming argument array,

sub parseAutorep { print join "\n", map defined ? "'$_'" : '<undef>', @_; }

your output will be

'Util' 'parse'
This is because (as documented in perlsub):
If a subroutine is called using the & form, the argument list is optional, and if omitted, no @_ array is set up for the subroutine: the @_ array at the time of the call is visible to subroutine instead. This is an efficiency mechanism that new users may wish to avoid.
The solution is to include parentheses in your call if you really want a null argument list. Alternatively, if you'd like the option of passing additional arguments, you could just shift both the package and subroutine name off the argument stack:
sub dispatch { my ($self, $fname) = (shift,shift); &{$dispatchTable{$fname}}; }


Comment on Re: strange code (de)referencing behavior
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://953060]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2014-12-21 22:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (108 votes), past polls