Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: sort a csv file then update the same file

by Laurent_R (Monsignor)
on May 29, 2014 at 09:47 UTC ( #1087773=note: print w/ replies, xml ) Need Help??


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

Other possible ways to do it:

1. open your file in read mode, sort the content in memory, close the file, and reopen it in write mode;

2. I usually prefer to keep a copy of the original file, just in case something goes wrong. So I rename the original file (changing the extension to .bak, for example), and then open the renamed original in read mode and write to a new file having the original name (this is basically what the -i command line option does in Perl one-liners). The renamed original file can be deleted at a later point, once it has been verified that everything went right.


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://1087773]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2015-07-31 08:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (276 votes), past polls