Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PERL Parse CSV

1 view
Skip to first unread message

mmitt...@gmail.com

unread,
Sep 20, 2006, 6:46:55 AM9/20/06
to
Need help folks.

I have a csv file that has some fields containing "," as part of the
field and not a delimiter. These fields are double quoted. What I
need to do is read each line, if the value in field 22 = X dont print
$line move
on to the next line. I am unable to use split to get the field I want
as some fields as I said are double quoted and contain "," in them.
example: "Potsdam, NY"

This one is driving me crazy.

I have only gotten about this far:
use Text::ParseWords;

while (@ARGV) {
$file=shift (@ARGV);
open (IN,"$file") unless ($file =~ /\.Z/);
while (defined($line = <IN>)) {
@fields =quotewords(',', 0, $line);
print "@fields[22]\n";

}
}
I have also tried the regex for csv files from Mastering Regex.

One thought was use a hash...

Any help or suggestions would be appreciated.

Thanks

Paul Lalli

unread,
Sep 20, 2006, 7:01:13 AM9/20/06
to
mmitt...@gmail.com wrote:
> Need help folks.
>
> I have a csv file that has some fields containing "," as part of the
> field and not a delimiter. These fields are double quoted. What I
> need to do is read each line, if the value in field 22 = X dont print
> $line move
> on to the next line. I am unable to use split to get the field I want
> as some fields as I said are double quoted and contain "," in them.
> example: "Potsdam, NY"
>
> This one is driving me crazy.
>
> I have only gotten about this far:
> use Text::ParseWords;

As far as I know, Text::ParseWords is used to parse a line the way the
shell would see it. Not the same as CSV.

Try Text::CSV instead.

Paul Lalli

0 new messages