Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: What's missing in Perl 5.10

by Roy Johnson (Monsignor)
on Dec 20, 2007 at 21:33 UTC ( [id://658282]=note: print w/replies, xml ) Need Help??


in reply to Re: What's missing in Perl 5.10
in thread What's missing in Perl 5.10

That made me want to implement it. Ironically, I don't have 5.10 installed yet, and there are a few features that would be appropriate here. Note that I reversed the result list, so that the order is key/value, like hash-each is.
use strict; use warnings; BEGIN { my %state; sub a_each(\@) { my $aref = shift; exists $state{$aref} or $state{$aref} = -1; if (++$state{$aref} > $#$aref) { delete $state{$aref}; return (); } else { return ($state{$aref}, $aref->[$state{$aref}]); } } } my @array = qw( foo bar rat ); while (my ($idx,$val) = a_each @array) { print "$val at $idx\n"; }

Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (9)
As of 2024-03-28 12:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found