From: "Mihir Kamdar" <[EMAIL PROTECTED]> > I have a csv file. I wanted to do some calculations on some of its fields, > like multiplying the 7th field with the 13th field and overwriting the 13th > field with the answer of my calculation. > > Regarding this, can I do the calculations on the input file and overwrite it > after calculating, or I will have to open the output file and write into it? > I am asking this because I will have several files in the directory. So, I > will have to read the directory using readdir, and process each file. It is > better if I open the file in read-write mode, process it and overwrite the > file. Just wanted to know if it is safe?
I think you should use either DBD::CSV or DBD::AnyData and SQL to make your changes. Something like #!/usr/bin/perl use strict; use DBI; my $dbh = DBI->connect("DBI:CSV:f_dir=/dir/with/the/csvs") or die "Cannot connect: " . $DBI::errstr; $dbh->{'csv_tables'}->{'SomeName'} = { 'file' => 'SomeName20070827.csv'}; # tie the table name to the filename my $sth = $dbh->prepare('UPDATE SomeName SET Foo = Foo * Bar'); $sth->execute(); # specify an execute the action __END__ And that's it. Let the modules do the heavy work for you. Jenda P.S.: If you do not know SQL, learn it! You can be a productive programmer without knowing anything about XML or whatever's the current hype, you can't be one without SQL. ===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz ===== When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/