Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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 taking refuge in the Monastery: (7)
As of 2014-12-25 08:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls