Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: mutliplying each element of a list by the same number

by olus (Curate)
on May 15, 2008 at 14:06 UTC ( [id://686734]=note: print w/replies, xml ) Need Help??


in reply to mutliplying each element of a list by the same number

for (0..$#ratio_list){ $ratio_list[$_] *= 10; }

This does not filter values that are 0, but does multiply every element of the array by 10. Not sure if you really want to filter zeroes.

Replies are listed 'Best First'.
Re^2: mutliplying each element of a list by the same number
by pc88mxer (Vicar) on May 15, 2008 at 15:58 UTC
    This is just slightly more efficient (at least in terms of keystrokes if not execution time):
    for (@ratio_list) { $_ *= 10 }
    If you wanted to simultaneously create @minutes_list, you can use:
    for (@ratio_list) { ($_ *= 10) && push(@minutes_list, $_) }
      for (@ratio_list) { $_ *= 10 }

      If you're going to do that, why not get rid of useless punctuation altogether?

      $_ *= 10 for @ratio_list;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://686734]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-19 04:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found