Tolgar
asked on
How to subtract a number from all elements of an array in Perl?
How can I subtract 2 from all elements of an array without writing an explicit foreach loop?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oops. Thinko. Mine should obviously be -= and - (instead of += and +). I hate the limited edit time on EE.
When you say "without writing an explicit foreach loop", I'm not sure if you'd prefer an implicit foreach loop, or an explicit map loop, or to invoke code that someone else has already written, but you could also
use Operator::Util qw(hyper);
hyper('-=', \@arr, 2, dwim_right=>1) ;
use Operator::Util qw(hyper);
hyper('-=', \@arr, 2, dwim_right=>1) ;