Google 그룹스는 더 이상 새로운 유즈넷 게시물 또는 구독을 지원하지 않습니다. 과거의 콘텐츠는 계속 볼 수 있습니다.

PERL Parse CSV

조회수 1회
읽지 않은 첫 메시지로 건너뛰기

mmitt...@gmail.com

읽지 않음,
2006. 9. 20. 오전 6:46:5506. 9. 20.
받는사람
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

읽지 않음,
2006. 9. 20. 오전 7:01:1306. 9. 20.
받는사람
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개