Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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

by rob_au (Abbot)
on Aug 25, 2002 at 22:35 UTC ( #192724=categorized answer: print w/replies, xml ) Need Help??

Q&A > subroutines > Why does my subroutine not receive the scalar parameter as $_? - Answer 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;

Log In?

What's my password?
Create A New User
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (13)
As of 2017-02-23 14:46 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (347 votes). Check out past polls.