GertMT has asked for the wisdom of the Perl Monks concerning the following question:
data.txt#!/usr/bin/perl -w use strict; use diagnostics; use Text::CSV_XS qw( ); my $qfn_in = 'data.txt'; open( my $fh_in, '<', $qfn_in ) or die("Can't open file \"$qfn_in\": $!\n"); my $fh_out = \*STDOUT; my $csv_in = Text::CSV_XS->new( { sep_char => ',', eol => $/ } ); my $csv_out = Text::CSV_XS->new( { eol => $/ } ); my $selection = "Apple"; my $code = " ####"; my $filter = "CX89"; while ( my $row = $csv_in->getline($fh_in) ) { if ( $row->[1] eq $selection ) { $code = "tree"; if ( $row->[0] eq $filter ) { $fh_out->print("$row->[0] $row->[1] $code \n"); } } }
"CX89",Apple "CX89",Sailing "CX89",Apple "AC75",Apple "CX89",Sailing
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: parsing CSV with TEXT::CSV
by Anonymous Monk on Jul 22, 2009 at 13:12 UTC | |
by GertMT (Hermit) on Jul 22, 2009 at 15:22 UTC | |
by Anonymous Monk on Jul 23, 2009 at 01:00 UTC |