Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by BrowserUk (Pope)
on Jun 17, 2011 at 20:45 UTC ( #910256=note: print w/ replies, xml ) Need Help??


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

I think I've settled on requiring that the iterator be called in a list context. Eg.:

sub i{ my $n = shift; return sub{ $n ? $n-- : () } };; $i = i( 5 ); print $_ while ( $_ ) = $i->();; 5 4 3 2 1

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.


Comment on Re^3: Dumb, non-question: How to return 'nothing'.
Download Code
Re^4: Dumb, non-question: How to return 'nothing'.
by SuicideJunkie (Priest) on Jun 17, 2011 at 21:05 UTC
    Would be worthwhile to add carp "Iterator not called in list context" unless wantarray; so it can't be used improperly?

      Excellent notion. Thanks.


      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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2014-09-20 14:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (160 votes), past polls