Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^5: How to determine if an array contains an undef value?

by Anonymous Monk
on Jan 05, 2015 at 22:23 UTC ( [id://1112238]=note: print w/replies, xml ) Need Help??


in reply to Re^4: How to determine if an array contains an undef value?
in thread How to determine if an array contains an undef value?

If $val is undef the loop ends
$ perl -MO=Deparse -le " while (my $val = shift @array) { print $val } + " BEGIN { $/ = "\n"; $\ = "\n"; } while (my $val = shift @array) { do { print $val }; } -e syntax OK

$error_count++ and next if some_condition();

Comma to the rescue

$error_count++, next if some_condition();

Replies are listed 'Best First'.
Re^6: How to determine if an array contains an undef value?
by Laurent_R (Canon) on Jan 05, 2015 at 23:22 UTC
    If $val is undef the loop ends
    Yes, right (++), although there are many cases where you know this can't happen. But you are absolutely correct, $val may also be "0" or "", and that is more common. This syntax is broken or at best very dangerous. Which is the reason, BTW, why I would rather use the syntax of first example above, which does not have this problem. I've just corrected my post to strike out this example. Thanks for calling my attention on this.

    Comma to the rescue
    Yes, thanks, I know you can do that, I was just trying to give an example of a stupid mistake I did 4 or 5 years ago when trying to be too clever.

      Hello Laurent_R,

      Thank you for your time and effort you examples are enlightening to me.

      Thank you for your time and effort.

      Seeking for Perl wisdom...on the process of learning...not there...yet!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-25 20:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found