in reply to Re^2: A classic use of prototypes: map2
in thread A classic use of prototypes: map2

You get trouble with undefined quantities if you go beyond the minimum last index. Your updated code still uses @$arrayref instead of $#$arrayref as the last index of the referenced array.

After Compline,
Zaxo

  • Comment on Re: Re^2: A classic use of prototypes: map2

Replies are listed 'Best First'.
Re^4: A classic use of prototypes: map2 (<)
by tye (Sage) on May 02, 2004 at 15:27 UTC

    Since < is used, @$aref is correct. Using $#$aref would work if <= were used. I prefer the former. But for that case the variable shouldn't be called "last index" and in the current code (that appears to keep changing -- so I'm not claiming you were mistaken) it isn't ($rv_len).

    FYI, Algorithm::Loops includes several flavors of 'mapcar' which are like map2 but take N lists and pass the items into the code block via @_. The module documentation also discusses why I chose to use prototypes despite usually avoiding them.

    - tye