Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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 surveying the Monastery: (14)
As of 2014-09-18 13:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (115 votes), past polls