in reply to Re: foreach .. stepping?
in thread foreach .. stepping?

Hi,

But the fastest solution is using a closure:

sub step { my $step=shift; my $count=0; my @array=@_; return sub { $return=$array[$count]; $count+=$step; return $return }; }; for ( my $s=step(5,2..100); my $res=&$s ; 1 ) { print "$res "; }
My benchmark shows 6 times faster than the map, and 10 times faster than the step method.

The reason is that I transfer an array only once, and than do queries in the array, whilst with map or step, one iterates over more than one array (map/grep and foreach).
---------------------------
Dr. Mark Ceulemans
Senior Consultant
IT Masters, Belgium