Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Pass an optional parameter to a subroutine

by robartes (Priest)
on Sep 15, 2006 at 08:17 UTC ( #573069=note: print w/ replies, xml ) Need Help??


in reply to Pass an optional parameter to a subroutine

You're being bitten by the fact that 0 is false, so if you pass 0 in $db_write, the shift || 1 sees false || 1 and you get 1.

You will probably want to explicitely check for definedness instead:

my $ref_mail = shift; my $db_write = shift; # If $db_write is defined, use that, otherwise default to 1 $db_write = defined($db_write)?$db_write:1;

CU
Robartes-


Comment on Re: Pass an optional parameter to a subroutine
Select or Download Code
Re^2: Pass an optional parameter to a subroutine
by ocs (Monk) on Sep 15, 2006 at 08:52 UTC
    Wow, thank you guys. That was really fast & you got my problem solved. Great community :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2015-07-04 20:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls