Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^8: Pre-process csv files before using

by DrAxeman (Beadle)
on Aug 07, 2005 at 02:44 UTC ( #481597=note: print w/replies, xml ) Need Help??


in reply to Re^7: Pre-process csv files before using
in thread Pre-process csv files before using

Just one quick question. How about if I wanted to keep the original file intact, and have this create a new file with the modified data (over-writting an existing file if it exists)?

Say it reads, data.csv and writes a new file named <origional-file-name>-ready.csv (or something like that). This way, if there is an error, I can re-run the perl script with out having to re-copy the data.
--Scratch that--
I figured out that there is a rename() function.
  • Comment on Re^8: Pre-process csv files before using

Replies are listed 'Best First'.
Re^9: Pre-process csv files before using
by sk (Curate) on Aug 07, 2005 at 03:47 UTC
    You are making it complicated by doing a rename and in place edit.

    I would do -

    open (IN, 'origdata.csv'); # Open the file for read open (OUT,'>','copy.csv'); # Open the file for write. Will overwrite +if exists while(<IN>) { # read contents of input file # <IN>, typucally used inside a while will populate variable $_ # more proecessing print OUT ($_); # Write out to new file }

    I think you should start reading more about how to work with files and other perl idioms.

    I would recommend that you start with "Learning perl book". Also there are lot of stuff in Categorized Questions and Answers section!

    -SK

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://481597]
help
Chatterbox?
[james28909]: how come it is so easy for me to not care what others think while others will mute themselves because they are scare they will be called ignorant or stupid

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2017-12-15 14:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (433 votes). Check out past polls.

    Notices?