Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: shift vs @_

by grep (Monsignor)
on Oct 02, 2006 at 18:36 UTC ( #575925=note: print w/ replies, xml ) Need Help??


in reply to shift vs @_

I will often use multiple shifts if I want to short circuit a sub when a non-true value is passed.

sub foo { my $bar = shift || return; my $baz = shift || return '<p style="font-color:red">BAD</p>'; }

Again I'll note that this works only for non-true values, IOW if 0(zero) is acceptable then don't do this.



grep
Mynd you, mønk bites Kan be pretti nasti...


Comment on Re: shift vs @_
Select or Download Code
Replies are listed 'Best First'.
Re^2: shift vs @_
by ikegami (Pope) on Oct 02, 2006 at 21:14 UTC

    if 0(zero) is acceptable then don't do this.

    More specifically, if one of the following is acceptable, then don't do this:

    • 0 (numeical zero),
    • '0' (the string consisting exactly of the character zero),
    • '' (the zero-length string),
    • undef (the undefined value), or
    • something that evaluates to one of the above in boolean context
Re^2: shift vs @_
by exussum0 (Vicar) on Oct 02, 2006 at 20:59 UTC
    'careful, perl's true may not coincide with real true. "0" and 0 are equivs.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2015-07-31 01:26 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 (274 votes), past polls