Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^6: Dumb, non-question: How to return 'nothing'.

by ikegami (Pope)
on Jun 18, 2011 at 06:20 UTC ( #910302=note: print w/ replies, xml ) Need Help??


in reply to Re^5: Dumb, non-question: How to return 'nothing'.
in thread Dumb, non-question: How to return 'nothing'.

No, the loop won't exit even if [ undef ] or [ 0 ] is returned. List assignment in scalar context returns the number of elements to which its RHS evaluates, meaning the number of elements in the array.

You'd be right that

while( my $next = $iter->() ) { my @next = @$next; ... }

is not equivalent to

while( my @next = @{ $iter->() } ) { ... }

But that's not the situation here.

The point was that

while( my $next = $iter->() ) { ($next) = @$next; ... }

is a complicated version of

while( my $next = @{ $iter->() } ) { ... }

which is just an expensive version of

while( my ($next) = $iter->() ) { ... }


Comment on Re^6: Dumb, non-question: How to return 'nothing'.
Select or Download Code
Re^7: Dumb, non-question: How to return 'nothing'.
by Anonymous Monk on Jun 18, 2011 at 06:47 UTC
Re^7: Dumb, non-question: How to return 'nothing'.
by BrowserUk (Pope) on Jun 18, 2011 at 07:31 UTC
    The point was that while( my $next = $iter->() ) { ($next) = @$next; ... } is a complicated version of while( my $next = @{ $iter->() } ) { ... }

    Not so. In the latter case when the iterator returns undef to terminate iteration, you will attempt to dereference that undef causing an error.

    In the former, the loop terminates and the dereference is never reached.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      you will attempt to dereference that undef causing an error.

      ug, tired. Will strike that bit.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2014-07-10 00:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (197 votes), past polls