Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Text::CSV module, writing some data on a csv.

by Lotus1 (Vicar)
on Apr 06, 2016 at 15:43 UTC ( [id://1159731]=note: print w/replies, xml ) Need Help??


in reply to Text::CSV module, writing some data on a csv.

If you aren't familiar with array references you might try using the style below instead. It uses the parse() and fields() functions to get an array of the columns for each line.

open(my $data, '<', $file) or die "Could not open '$file' $!\n"; while (my $line = <$data>) { chomp $line; if ($csv->parse($line)) { my @fields = $csv->fields();

You could open an output file before the while loop, then after each line is parsed and @fields has values you can modify and print them to your new file.

There is a nice page about CSV at Perl Maven and this Perlmonks node seems very similar to what you are trying to do. A Google search for tutorials for this module turns up lots more.

Update: If you would like to modify existing csv files you might consider Tie::Array::CSV.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1159731]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-23 19:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found