Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Looking for appropriate Regex

by james2vegas (Chaplain)
on Apr 07, 2013 at 09:21 UTC ( #1027337=note: print w/replies, xml ) Need Help??

in reply to Looking for appropriate Regex

Not sure I follow exactly what the question is, but have you tried using Text::CSV to parse your CSV?

Replies are listed 'Best First'.
Re^2: Looking for appropriate Regex
by better (Acolyte) on Apr 07, 2013 at 12:54 UTC

    Yes, I did. Thanks!

    Here is the code I use for parsing the CSV file:

    #! /usr/local/bin/perl # #script opens and parses a CSV file, #removes carriage return #and writes all into a new text file # #tested: --ok! use strict; use warnings; use Text::CSV; #Input CSV filename my $file = $ARGV[0]; if (!$ARGV[0]) { $file = './data/IDs_test.csv'; #Default } if (!-f $file) { print "Can not find $file: $!\n"; exit 1; } #Parsing CSV local $/ = "\r\n"; #add windows carriage return to perl's eol +(newline) my $csv = Text::CSV ->new ({binary =>1, eol => $/}); open (my $fhCSV, '<', $file) or die "Can not open $file: $!\n"; open (my $fhOUT, '>', './data/IDs.txt') or die "Can not open: $!\n"; while (my $line = <$fhCSV>) { if ($csv->parse($line)) { my @fields = $csv->fields (); chomp (@fields); print $fhOUT "@fields\n"; } else { warn "Line could not be parsed: $line\n"; } } print "CSV parsed and saved as text file: /data/IDs.txt!"; close $fhCSV; close $fhOUT;

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2020-10-31 04:22 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (286 votes). Check out past polls.