Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: passing $_ to my function

by moxliukas (Curate)
on Sep 30, 2002 at 12:03 UTC ( #201688=note: print w/ replies, xml ) Need Help??


in reply to passing $_ to my function

Maybe something along the lines like:

sub my_sub { my $argument = shift || $_; # do things with $argument }

Be warned: I am not a Perl guru though


Comment on Re: passing $_ to my function
Download Code
Re: Re: passing $_ to my function
by davorg (Chancellor) on Sep 30, 2002 at 12:15 UTC

    That breaks if you pass an argument that evaluates as false. I'd do something like this:

    sub my_sub { my $arg = @_ ? shift : $_; # do stuff }
    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2014-09-16 22:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (51 votes), past polls