Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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

Replies are listed 'Best First'.
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 }

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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2016-10-26 12:10 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (340 votes). Check out past polls.