I don't know if this is gonna help much, but we'll see. If you need to be able to stop and resume functions, create your functions as the loops themselves. I've figured it out in my head, but that's the best I can word it. Maybe some pseudo code would help communicate my meaning...

Instead of using a model like the following...

# USING LOOPS (not gonna work right) my(@directives) = qw/ up down left right left down up right down left up right up down up down down up left left right right right right right left up down up up up up down down left down left up up down down left left left left left left left right up up down right left down down left right right right right right right left left left down up down up down up down up down down right right down up up up up up up up left left right up right left right left right left up down up down right left left left left right down up left right up up /; # "go up, go down, go right, left, etc... while (@directives) { go('^') while &where eq 'up'; go('v') while &where eq 'down'; go('<') while &where eq 'left'; go('>') while &where eq 'right'; } sub where { shift @directives } sub go { print @_ }

...Use a model like this...

# USING SUBS TO EMULATE LOOP ITERATIONS my(@directives) = qw/ up down left right left down up right down left up right up down up down down up left left right right right right right left up down up up up up down down left down left up up down down left left left left left left left right up up down right left down down left right right right right right right left left left down up down up down up down up down down right right down up up up up up up up left left right up right left right left right left up down up down right left left left left right down up left right up up /; my($directions) = { 'up' => sub { '^' }, 'down' => sub { 'v' }, 'left' => sub { '<' }, 'right' => sub { '>' } }; sub go { while (@_) { print &{ $directions->{ shift @_ } } } } go(@directives); # "go up, go down, go right, left, etc...
--
Tommy Butler, a.k.a. TOMMY

In reply to Re: complex iterator needed by Tommy
in thread complex iterator needed by japhy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.