in reply to Re: Pass an optional parameter to a subroutine
in thread Pass an optional parameter to a subroutine

Actually, I think that currently I'd write your code like this
my $ref_mail = shift; my $db_write = @_ ? shift : 1;

That's icky, as it means more to change if there are ever more parameters than just these two. I'd suggest:

my $ref_mail = shift; my $db_write = defined $_[0] ? shift : 1;
<radiant.matrix>
A collection of thoughts and links from the minds of geeks
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet

Replies are listed 'Best First'.
Re^3: Pass an optional parameter to a subroutine
by Velaki (Chaplain) on Sep 15, 2006 at 17:54 UTC

    Exactly! What if someone sent in something like this?

    foo(undef, 1, 2);
    Then the @_ version would shift off the undef, which is not what is wanted, I think.

    Being contemplative
    -v.

    "Perl. There is no substitute."