|Just another Perl shrine|
Re: multiplication a column of data in csv file by a factorby Laurent_R (Canon)
|on Apr 03, 2019 at 15:44 UTC ( #1232101=note: print w/replies, xml )||Need Help??|
First please note that the sprintf builtin does not print out anything: it only returns a formatted string. In your code, the call to sprintf does not do anything useful, since you're not using the return value. You need to either use print to print out the string produced by sprintf, or use printf.
Second, it seems that you're using sort with the aim to modify the values in your array of arrays, rather than for sorting purposes. That's not really the right tool for that. Use a for loop or a map statement (depending on whether you want to modify your data structure in place or create a new data structure).
Perhaps that's more or less what you looking for:
which produces the following output (which is presumably what you're looking for):
If you insist on reducing the number of code lines, you could do it directly (without the auxiliary arrays) like this:
or possibly with only one map statement (but the code doesn't get shorter):
I kept relatively close to your code to try to explain some of the problems in your script and show possible ways to solve them, but, as pointed out by choroba, using Text::CSV might be a good idea.
In Section Seekers of Perl Wisdom