Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl array manipulation

Tags:

arrays

perl

Is there a single line in perl which does some magic like this.

Array = [100,200,300,400,500];

percent = 50%

new_Array = [50,100,150,200,250];

That is, I give an array and specify a percent. And it should give me a new array with the given percent of original array values.

should take care of odd numbers and give me either ceiling or floor of that value.

I know how to do it manually. Just wondering if perl has something surprising in store?

Thank you.

like image 801
jerrygo Avatar asked Jul 14 '10 20:07

jerrygo


1 Answers

map will allow you to transform every item in a list.

my $percent = 50;
my @original = qw/100 200 300 400 500/;
my @manipulated = map { $_ * $percent / 100 } @original;
like image 125
Quentin Avatar answered Oct 13 '22 11:10

Quentin