Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: sort a csv file then update the same file

by Tux (Monsignor)
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


Comment on Re: sort a csv file then update the same file
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (13)
As of 2015-03-27 13:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When putting a smiley right before a closing parenthesis, do you:









    Results (607 votes), past polls