Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: sort a csv file then update the same file

by Tux (Abbot)
on May 29, 2014 at 09:36 UTC ( #1087771=note: print w/replies, xml ) Need Help??

in reply to sort a csv file then update the same file

The safe way would to be using a real CSV parser:

use Text::CSV_XS qw( csv ); my @sorted = sort { $a->[5] cmp $b->[5] || $a->[4] cmp $b->[4] } @{csv (in => "sorted.csv")}; csv (out => "sorted.csv", in => \@sorted);

Which could be shortcutted to

csv (in => [ sort { $a->[5] cmp $b->[5] || $a->[4] cmp $b->[4] } @{csv (in => "sorted.csv")}], out => "sorted.csv");

Enjoy, Have FUN! H.Merijn

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2016-10-25 20:48 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (330 votes). Check out past polls.