in reply to array looping with foreach
Advantages:my @arr = ( 110..117) ; # Generic array Iterator --- # Calls back $cb passing it a 2-element array : the INDEX, and an alia +s to the contents at that index sub iter{ my ($cb,$aref)=@_; # $cb is the callback sub ref passed in.. my $idx=0; for(@$aref){ $cb->($idx,$_); $idx++ } }; # Call the iterator iter(sub{print "ops : @_\n"},\@arr); # Prints: #ops : 0 110 #ops : 1 111 #ops : 2 112 # ....etc ...
"As you get older three things happen. The first is your memory goes, and I can't remember the other two... " - Sir Norman Wisdom
|
|---|