Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Re: Defined or Undefined - That is the question.

by michael (Sexton)
on Mar 13, 2001 at 21:51 UTC ( #64173=note: print w/ replies, xml ) Need Help??


in reply to Re: Defined or Undefined - That is the question.
in thread Defined or Undefined - That is the question.

Since an array returns its length in scalar context--which is the context that unless places the array in--an array of length 0 will return 0, or false. From reading Programming Perl, I thought that unless didn't permit a branching conditional. Can someone clarify this for a Perl newbie?


Comment on Re: Re: Defined or Undefined - That is the question.
Select or Download Code
(sacked: unless/else) Re: Re: Re: Defined or Undefined - That is the question.
by sacked (Hermit) on Mar 14, 2001 at 04:29 UTC
    On the top of page 23 in my Camel 2, it reads

    There is no "elsunless" though. This is generally construed as a feature.
    I believe the authors meant that there is no keyword that means "elsif (not EXPR)" in the way that "unless (EXPR)" means "if (not EXPR)." You can, however, use elsif and else with unless:
    foreach $a ( 0,1,2 ) { unless ( $a ) { print "a is 0 or undef\n"; } elsif ( $a == 1 ) { print "a is 1\n"; } else { print "a equals $a\n"; } } __END__ a is 0 or undef a is 1 a equals 2
    I hope this clears things up for you.

    --sacked

      Ah, yes. That does clear it up. (That's p. 31 on the 3d edition of the Camel.) Unfortunately, the Camel doesn't show that usage in the proximity.

      Thanks.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2014-08-30 21:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls