in reply to Re^4: Why is the following instance of Matching using an array element not working
in thread Why is the following instance of Matching using an array element not working
The script below is based upon the Text::CSV documentation:
use Modern::Perl; use Text::CSV; my @Sample_Ids_m; my $csv = Text::CSV->new( { binary => 1 } ) # should set binary att +ribute. or die "Cannot use CSV: " . Text::CSV->error_diag(); while ( my $row = $csv->getline(*DATA) ) { push @Sample_Ids_m, $row->[6]; # Element 6 is the ID } say for @Sample_Ids_m; # Print the collected I +Ds __DATA__ John Doe,G building,05-Aug-2012,08-Aug-2012,"New York City, NY",ABC234 +5,UCD23467, John Moe,H building,05-Aug-2012,08-Aug-2012,New York City,DEF2345,UCD8 +0645, John Slo,I building,05-Aug-2012,08-Aug-2012,New York City,GHI2345,UCD7 +6765, John Hor,j building,05-Aug-2012,08-Aug-2012,New York City,JKL2345,UCD8 +7111,
Output:
UCD23467 UCD80645 UCD76765 UCD87111
Adapted for your csv file (untested):
use Modern::Perl; use Text::CSV; my @Sample_Ids_m; my $csv = Text::CSV->new( { binary => 1 } ) # should set binary att +ribute. or die "Cannot use CSV: " . Text::CSV->error_diag(); open my $fh, "<", "Merged_CSVfiles.csv" or die "Merged_CSVfiles.csv: $ +!"; while ( my $row = $csv->getline($fh) ) { push @Sample_Ids_m, $row->[16]; # Element 16 is the ID } $csv->eof or $csv->error_diag(); close $fh; say for @Sample_Ids_m; # Print the collected I +Ds
From your code above, it looks like the ID is the 16th element in @columns, and the $row->[16] notation grabs it after parsing a csv line. See if this may assist your scripting...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Why is the following instance of Matching using an array element not working
by MyJeweledPerls (Initiate) on Aug 13, 2012 at 21:22 UTC | |
by Kenosis (Priest) on Aug 13, 2012 at 21:29 UTC |