Hello, I would like to parse a .csv file and write certain records into two separate files. The program below writes the records easily into the csvtmp.csv but the second file is only created with no records written. I cannot see the problem here, the second file is produced easily if the first loop is discarded. Any ideas? Thanks.
-L ====================================== #!/bin/perl use warnings; use strict; use Text::CSV_XS; use Tie::Handle::CSV; my $fh = Tie::Handle::CSV->new(csv_parser => Text::CSV_XS->new({binary => 1}), file => 'rek.csv', header => 1); #Write into the first file my $outfile = 'csvtmp.csv'; open (OUTFILE, ">", $outfile) or die $!; while (my $csv_line = <$fh>) { print OUTFILE $csv_line->{'Name'} . ": " . $csv_line->{'Surname'} . "\n"; } close OUTFILE; #Write into the second file my $outfile2 = 'csvtmp2.csv'; open (OUTFILE2, ">", $outfile2) or die $!; while (my $csv_line = <$fh>) { if ($csv_line->{'Company'} =~ m/Middle./) { print OUTFILE2 $csv_line->{'Surname'} . ": " . $csv_line->{'Company'} . "\n"; } } close OUTFILE2; close $fh; ====================================== -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/