Home > Archive > PERL Beginners > November 2006 > element-wise operations on array
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
element-wise operations on array
|
|
| oroszib@vpg.sulinet.hu 2006-11-01, 7:58 am |
| Hi!
Is there a simple way of multiplying all elements of an array/list with
a value, then store the result in a new array, or do I have to use loops?
--
Thanks in advance,
B.
| |
| John W. Krahn 2006-11-01, 7:58 am |
| OROSZI Balázs wrote:
> Hi!
Hello,
> Is there a simple way of multiplying all elements of an array/list with
> a value, then store the result in a new array, or do I have to use loops?
my @new_array = map $_ * $value, @array;
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
|
|
|
|
|