in reply to array add/sub/mult/div

One could do something like:
use mapcar; sub a_add { $v1 = [ mapcar { $_[0] + $_[1] } @_[0,1] ] } sub a_subt { $v1 = [ mapcar { $_[0] - $_[1] } @_[0,1] ] } sub a_mult { $v1 = [ mapcar { $_[0] * $_[1] } @_[0,1] ] } sub a_div { $v1 = [ mapcar { $_[1] ? $_[0] / $_[1] : undef } @_[0,1] +] }
That adds something to make sure you're not dividing by zero. It also allows both for a return value as well as a in-place change. (It actually requires in-place changes, which may not be desirable.)

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Replies are listed 'Best First'.
Re: Re: array add/sub/mult/div
by RMGir (Prior) on Mar 18, 2002 at 19:26 UTC
    One could, if one had mapcar.

    However, search.cpan.org does not admit to its existence...
    --
    Mike (Edit: OOPS! mapcar module. Nice!)