ng0177 has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks, my objective is to multiply a column of data in csv file by a factor of say 1.1E3 w/ as little code as possible . I therefore modified the example by Zaxo https://www.perlmonks.org/bare/?node_id=560284 to:
my @multi_array; push @multi_array, [split] for <DATA>; my @by_second = reverse sort {unity} @multi_array; for (@by_second) { print "@{$_}\n"; } sub unity { $b->[1] *= 1.1E3; #sprintf("%E", 0+$b->[1]); return 1;} __DATA__ 1.10000E0 1.00000E0 1.00000E0 2.20000E0 2.00000E0 2.00000E0 3.30000E0 3.00000E0 3.00000E0
This actually works but only sprintf does not. Any advice as to how to keep the scientific notation? Is the usage of "reverse sort" and "$b" a misuse for this purpose?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: multiplication a column of data in csv file by a factor
by choroba (Cardinal) on Apr 03, 2019 at 13:47 UTC | |
|
Re: multiplication a column of data in csv file by a factor
by hippo (Archbishop) on Apr 03, 2019 at 11:37 UTC | |
|
Re: multiplication a column of data in csv file by a factor
by Laurent_R (Canon) on Apr 03, 2019 at 15:44 UTC | |
|
Re: multiplication a column of data in csv file by a factor
by bliako (Abbot) on Apr 03, 2019 at 11:42 UTC | |
|
Re: multiplication a column of data in csv file by a factor
by ng0177 (Acolyte) on Apr 03, 2019 at 15:30 UTC |