in reply to array add/sub/mult/div
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.)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] +] }
------
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 |