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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With