in reply to Interesting Use for "state" Variables

Except that the next time you execute the same loop, you know $i will not start over at 0, don't you?? :-)
[]s, HTH, Massa (κς,πμ,πλ)
  • Comment on Re: Interesting Use for "state" Variables

Replies are listed 'Best First'.
Re^2: Interesting Use for "state" Variables
by liverpole (Monsignor) on Mar 10, 2009 at 08:38 UTC
    Yes, you're right. That "fly in the ointment" just now occurred to me, and I was going to update my post to point this out. It unfortunately makes many applications (such as tracking line numbers from a file) useless, except for the very first time.  Rats.

    It brings me back to a previous thought -- I wonder what it would take to implement a special Perl variable to track the loop count? For example, $* is now deprecated; perhaps it could be "reused" for something like this?

    Anyway, thank you for finding my flaw early on.


    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/