Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Can I check if a loop's scope is entered for the first time?

by Veltro (Hermit)
on May 07, 2018 at 22:40 UTC ( [id://1214173]=note: print w/replies, xml ) Need Help??


in reply to Can I check if a loop's scope is entered for the first time?

Hi, was experimenting with your code, couldn't solve it but here are my 2 cents.

use strict ; use warnings ; use Data::Dumper ; my @limit = (reverse 1..5) ; my $limit = { _l => \@limit } ; bless ( $limit, 'limit' ) ; sub countdown { my $val = shift ; my $iter = sub { if ( $val-- ) { $_[0] = $val ; return 1 ; } return ; } ; return $iter ; } while ( my $iter = $limit->Next( *countdown ) ) { while ( $iter->( my $a ) ) { print "$a: " ; } print "\n" ; } package limit ; use strict ; use warnings ; use Data::Dumper ; sub Next { my $this = shift ; if ( @{$this->{_l}} ) { return $_[0]->( shift @{$this->{_l}} ) ; } return ; } ;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-23 21:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found