For parsing comma separated values, I think that Text::ParseWords could serve you well? Instead of split(/,/,$_) below, you might need parse_csv($_)? parse_csv should produce a list that you can use like I did below (assign multiple values on the left of the "=" sign).
Your question about a different export character is insightful and very smart! If you have control over that, then get the report with say ^ delimited fields instead of ", then all these problems about quotes within quotes, etc. just go away! Just split on /^/ instead of /"//,/! I think that is the most simple and best idea yet! If you can get that, then just follow the example below (of course without my mistakes!-sorry I messed the row order up somehow..but you will figure it out...)
#!/usr/bin/perl -w use strict; while (<DATA>) { my ($num,$date,$category,$os,$subcat,$action,$desc,$assignto, $status,$extra) = split(/,/,$_); $num ||= ""; print "NUM: $num\n"; $date ||= ""; print "DATE: $date\n"; $category ||= ""; print "CATEGORY: $category\n"; $subcat ||= ""; print "SUBCAT: $subcat\n"; $os ||= ""; print "OS: $os\n"; $desc ||= ""; print "DESCR: $desc\n"; $action ||= ""; print "ACTION: $action\n"; $assignto ||= ""; print "ASSIGNTO: $assignto\n"; $status ||= ""; print "STATUS: $status\n"; $extra ||= ""; print "Extra: $extra\n"; print "\n"; } __DATA__ 456,05-Dec-2002,80,Software,print,,he can't print hes getting error ms +g: 'LPTTS FOR EC-2-1,paper jam,1,C 457,05-Dec-2002,22,Software,switchb.,,when internal call to ext 444 it + goes to switchboard2 - when internal call to 0 it goes to switchboar +d1 -- both should go to switchboard 1,call texchnitian - fixed ,35,C Prints: NUM: 456 DATE: 05-Dec-2002 CATEGORY: 80 SUBCAT: print OS: Software DESCR: he can't print hes getting error msg: 'LPTTS FOR EC-2-1 ACTION: ASSIGNTO: paper jam STATUS: 1 Extra: C NUM: 457 DATE: 05-Dec-2002 CATEGORY: 22 SUBCAT: switchb. OS: Software DESCR: when internal call to ext 444 it goes to switchboard2 - when + internal call to 0 it goes to switchboard1 -- both should go to swit +chboard 1 ACTION: ASSIGNTO: call texchnitian - fixed STATUS: 35 Extra: C
In reply to Re^5: Text::CSV_XS and "binary" mode
by Marshall
in thread Text::CSV_XS and "binary" mode
by bittis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |