in reply to foreach array manipulation

I would say this is as it should be. As it allows you to change the values of the array with foreach loop, which is faster than others (for or while).

Replies are listed 'Best First'.
Re^2: foreach array manipulation
by blazar (Canon) on Jan 26, 2005 at 08:47 UTC
    As it allows you to change the values of the array with foreach loop, which is faster than others (for or while).
    Huh?!? Maybe I misunderstood the sense of your words, but C<for> and C<foreach> are just synonims. Or were you referring to C-style C<for>'s (C<while>'s in disguise)?!?
      According to the people "who wrote the book on Perl" {grin}, there is indeed a "for" loop (what you would call "C style"), and a "foreach" loop (stolen mostly from C-shell). Even though the keywords of "for" and "foreach" are interchangeable, we call a foreach loop a foreach loop even when it's spelled "f-o-r".

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

        Indeed it's a matter of user interface[*]. While
        foreach (my $i=0; i<10;$i++) { #...
        does indeed work thus illustrating the point I was talking about, C<for> is IMHO more intuitively appropriate. OTOH many perl programmers, and I for one, always use C<for> instead of C<foreach> for the perlish form. Which is one of the reasons why Larry chose to only have C<for> and a separate keyword, namely C<loop> for C-style loops, in Perl6, that is.

        [*]I'm thinking especially of that paragraph of Conways's in which he mentions another book on general UIs and talks about how if you have a door that must be pulled then you'd better put a handle on it and if must be pushed then something flat instead (sorry for the bad wording, could not come with anything better!)

      Yup, i do call '($i=0;$i<$j;$i++) {}' a for loop and 'foreach (@list) {}' a foreach loop. I don't use 'for (@list) {}' inorder to avoid confusion like this :).

      But thanks for merlyn for info on what others think.