Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Answer: Why does my subroutine not receive the scalar parameter as $_?

( #192724=categorized answer: print w/ replies, xml ) Need Help??

Q&A > subroutines > Why does my subroutine not receive the scalar parameter as $_? contributed by rob_au

You are so close on this one - From perlsub ...

Any arguments passed to the routine come in as the array @_. Thus if you called a function with two arguments, those would be stored in $_[0] and $_[1]. The array @_ is a local array, but its elements are aliases for the actual scalar parameters.

So, if you are wanting to access the passed parameters directly, you will want to use $_[0] or alternately shift off values from the @_ array. eg.

sub get_long_count { my ($dd, $mon, $yyyy, $bc) = split /-/, $_[0], 4;

Comment on Answer: Why does my subroutine not receive the scalar parameter as $_?
Select or Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (12)
As of 2014-11-26 17:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (172 votes), past polls