Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: truth in while condition

by LanX (Archbishop)
on Sep 30, 2018 at 21:55 UTC ( #1223337=note: print w/replies, xml ) Need Help??


in reply to Re: truth in while condition (updated)
in thread truth in while condition

> you were testing "0\n" in the while-loop conditional and not the truly false string "0".

The following iterator returns no "\n" but still fails to stop at "truly false" number 0.

see explanation here

use strict; use warnings; use feature 'say'; my $i = Iterator->new([1,0,2,undef,3]); while ( <$i> ) { say "<$_>"; } package Iterator; use overload '<>' => sub { shift @{$_[0]} }; sub new { my ($class,$obj) =@_; bless $obj, $class; }

-->

<1> <0> <2>

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2019-07-15 18:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?