Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: How can I create an iterator that works inside foreach() (updated)

by hv (Prior)
on Nov 05, 2022 at 04:04 UTC ( #11147983=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    sub range {
      my($start, $end) = @_;
      return sub {
    ...
    
    my $it = range(3, 5);
    for (my $value; $value = $it->(); ) { say $value }
    
  2. or download this
    sub list_range {
      my($start, $end) = @_;
      return sub { $start .. $end };
    ...
    
    my $lit = list_range(3, 5);
    for ($lit->()) { say $_ }
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (1)
As of 2023-06-05 00:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (22 votes). Check out past polls.

    Notices?