http://www.perlmonks.org?node_id=201688


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 }
    --
    <http://www.dave.org.uk>

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