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

    Thanks again Kenosis and thanks to everyone who replied. I was able to fix my program finally. I made a lot of modifications from my original program. Using the CSV module was a much better strategy for getting out the total number of sample_ids. I did find it very helpful to go back and check that all my arrays and hashes were storing what they in fact were storing.Thanks again for all your suggestion

    I made a hash table with the sample_Id as keys and the line of text from the Merged_File with the sample id as a value. I used dumpvalue to display my hash contents and used a hash slice to print out the specific values I needed. Thanks to everyone dave

    use Dumpvalue; %id_lookup_table = map { ($Merged_Ids[$_], $merged_array[$_]) } 0..$#M +erged_Ids; my $dumper = Dumpvalue -> new; $dumper -> dumpValue(\%id_lookup_table); open(ERRORREPORT,"+<","reported_list.csv") or die "reported_li +st.csv: $!"; print ERRORREPORT @id_lookup_table{(@sample_ids)}; close ERRORREPORT; 'UCD12-00242-P' => "\"Joe Schmie\",ABD032,12-Feb-12,23-Feb-12,\"Whale +Tail Island, Fictitious Place\",USA,California,etc

      You're most welcome, Dave, and it's good to hear that you have your program working well now!