in reply to Why is the following instance of Matching using an array element not working

Without seeing any sample input, the following is just guesswork.

You're currently matching the entire record against the fourth ID; I think you want to match the fourth element of each record against all IDs.

I suspect

foreach my $records(@merged_array){ if($records =~ /$sample_ids[3]/){ print $records; } }

should probably be more like

foreach my $records (@merged_array) { my @elements = split /,/, $records; for my $sample_id (@sample_ids) { if ($elements[3] =~ /$sample_id/) { print $records; } } }

-- Ken

Replies are listed 'Best First'.
Re^2: Why is the following instance of Matching using an array element not working
by MyJeweledPerls (Initiate) on Aug 10, 2012 at 19:19 UTC

    You were right I need to match the fourth element against each of the records. I added the code you suggested and no value was returned I decided to do a check and I did this:

    foreach my $records (@merged_array) { my @elements = split /,/, $records; print $elements[0];
    The Output from this was:  "John Doe"John Doe"John Doe"John Doe"John Doe

    I realized that some of the fields themselves had commas within and that I couldn't consistently get the field I wanted by "print18" in this case So back to the drawing board for the next few minutes