Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: check undef

by linuxer (Deacon)
on Jun 23, 2009 at 09:33 UTC ( #773925=note: print w/ replies, xml ) Need Help??


in reply to check undef

If you have to do these checks again and again, you can think of creating a dedicated sub routine for that.

sub all_defined { for my $i ( @_ ) { #return 0 if !defined $i; return if !defined $i; } return 1; } if ( all_defined( $WCkey, $SCkey, $Pkey, $Wkey, $Ukey ) ) { print "bla bla"; }

Update: modified code; thanks davorg


Comment on Re: check undef
Download Code
Re^2: check undef
by davorg (Chancellor) on Jun 23, 2009 at 09:40 UTC

    return 0 has a potentially dangerous effect. It will evaluate as true if your subroutine is called in list context. Just a bare return is usually a better idea.

    --

    See the Copyright notice on my home node.

    Perl training courses

      Not better, different. Now it breaks under different circumstances.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2015-07-01 19:43 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 (17 votes), past polls