in reply to Re^6: Perl Internals - references and symbol table
in thread Perl Internals - references and symbol table

Along those lines. I don't like the idea of it leaking across scopes. The version I have is a little different. It actually stringifies the reference and caller info to avoid collisions. Using only the ref causes side effects at a distance.
my @array = (1..12); while(my @els = elements @array, 3 ){ last if grep { $_ eq 2 } @els; } my @five = elements @array 5; # Would get (4,5,6,7,8)!DWIM
Using both fixes this problem but can still suffer if the iterative construct is exited prematurely.
{ while (my @els = elements @giantarray, 10 ){ # Do stuff last if $els[0] == $somecondition; } redo if $someothercondition; }
The later probably almost never occur in most code, but when it does, I'm sure it would take much head scratching before deciding where the problem lies.

-Lee

"To be civilized is to deny one's nature."

Replies are listed 'Best First'.
Re^8: Perl Internals - references and symbol table
by Aristotle (Chancellor) on Nov 19, 2002 at 23:48 UTC
    How about you do as Perl's own each then? It will "leak" the iterator all over the entire program as well - but you can call keys or values to reset it.

    Makeshifts last the longest.

      I could do that, but there to my knowledge keys and each doesn't work on arrays.
      Even if you could though, it won't fix other problems. The easist way would be to simply say in the POD, "Don't do that!". There are many ways around it, It just vexes me that I can't have it DWIW. What would work I suppose is just to have a $^global that was set locally within loop conditions (modifying PP_CTL?), or extend Want.pm to add the context. I actually started modifying Want and for some reason put it aside. This would let you determine the "iterative" context but then, even if it was accepted, it would only be available in the latest perls. It's just one of those problems that gnaws at me. I keep thinking there has got to be some way of doing it without patching the source.

      -Lee

      "To be civilized is to deny one's nature."