Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • But doesn't Perl 5 violate the "one at a time" definition? I mean, you're not iterating over one element at a time. You're slurping a list, and THEN iterating over that list.

    In this example, keys is not the iterator; foreach is. each is a hash's iterator.

    • Right, I understand that. What I mean is that the keys operation happens first and THEN foreach iterates over ALL the values returned by keys, rather than one at a time.
      • I think you are right. Perl 5 really lacks a good syntax for iterating over data structures (that are not lists, arrays). Perhabs the best way is to overload the diamond operator to work on any data structure.

        Iteration with while in Perl can be nice, but it really only works for data structures that can't include values which Perl considers false. As soon as you get to while(defined(...)) Perl is clunky, too.

        Perl 6 will probably get it right, but if we're fair the next version of Java (1.5) will also introduce a foreach loop that does the right thing for collections.