in reply to Regexp nightmare with CSV
Case 1 - permanent regex:
for my $line (@lines_from_data_file) { my($idx,$fname,$sname,$loc,$time) = $line =~ /^(\d+),("[^"]+"),("[^"]+"),("[^"]+"),(.*)$/; }
Case 2 - one-liner to modify delimiters (in place)
perl -i.bak -ne "s/([\d\x22]),/$1.'|'/eg;print" datafile # for some reason I can't use single quotes for a # perl -e on Win32 so I have to use \x22 for "
Case 3 - just realised you can use the regex above (slight mod.) for your split.
I still suggest that case 2 is your best option - you're just making more work for yourself if you don't.@data = split /([\d"]+),/;
"Argument is futile - you will be ignorralated!"
|
|---|