Eric Roode wrote:
> >
> >Also the ability to traverse multiple lists at once
> >
> >  for ($a,$b,$c) (zip(@a,@b,@c)) { ... }
>
> I don't get it. This is a great advantage over:
>    @looparray = zip(@a,@b,@c);
>    while ( ($a,$b,$c) = splice (@looparray, 0, 3))
> ?
>
Because splice() is destructive, the 1st of your 2 lines would have to do a
full copy (otherwise based on the zip() RFC it would be lazily evaluated
without a copy). Doing a full copy would destroy the efficiency of such an
algorithm.

> I'm thinking that if I were implementing such a loop, I'd probably
> have set up my data structures so that instead of three arrays, I'd
> have one array of three hash elements, and iterate over it:
>
>     for $iter (@data)
>     {
>         foo ($iter->{a}, $iter->{b}, $iter->{c});
>     }
>
I wouldn't have thought this would be a good idea. The for (...) zip(...)
construct may be used to transpose a matrix stored as an array, or maybe the
lists are slices of other lists. It's the kind of construct one would see in
numeric programming all the time. Using a hash would both destroy the
efficiency of the program, and would also make other transposes, slices,
diagonals, etc very unwieldy.


Reply via email to