Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
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 ( #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? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2022-08-09 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?