in reply to I want to write a method that can be used with 'while ($thing = getNextThing() )'

The name of such a thing is iterator. It's usually implemented as a closure. Now you can start searching for the two terms.

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
  • Comment on Re: I want to write a method that can be used with 'while ($thing = getNextThing() )'
  • Download Code

Replies are listed 'Best First'.
Re^2: I want to write a method that can be used with 'while ($thing = getNextThing() )'
by Anonymous Monk on Aug 20, 2016 at 07:27 UTC

    For example, this one goes in circles

    my $coco = do { my @colors = qw[ pink maroon green OliveDrab4 PaleVioletRed3 RosyB +rown2 PeachPuff4 WhiteSmoke azure3 chartreuse1 coral3 gold1 firebrick +4 linen salmon4 tomato2 ]; my $ix = 0; my $size = int(@colors) ; sub { my $mod = $ix % $size; my $cix = $mod; warn "$ix $cix $colors[ $cix ]\n"; $ix++; return $colors[ $cix ]; }; }; $coco->() for 1 .. 100;

      Thanks! Got it working now.