in reply to nested loops to compare 2 files is only looping a limited number of times.

This might be a moot point now but here a possible solution...
#!/usr/bin/perl use strict; my $file_1 = <<FILE_1; Alan,Bloggs,06/11/2009,11/30/2011 David,Smith,06/08/2009,09/30/2012 Rosario,Anotherone,06/05/2009,11/30/2011 Angela,Madeupname,06/11/2009,07/31/2010 Ugochukwu,Smith,06/01/2009,10/31/2012 Amarjit,Patel,08/19/2008,11/30/2011 Missing,Man,08/12/2007,12/01/2013 Julie,Schmidt,05/01/2009,09/30/2012 Waseem,Alder,06/11/2009,11/30/2011 FILE_1 my %file_1; open( my $fh, "<", \$file_1 ) or die "Could not open file_1\n"; while (<$fh>) { chomp; my @cols = split ","; $file_1{"$cols[0] $cols[1]"} = $_; } close( $fh ); while (<DATA>) { chomp; my @cols = split ","; my $temp_name = "$cols[1] $cols[2]"; if (grep /$temp_name/, (keys %file_1)) { my $result = "$cols[0]," . join ",", $file_1{$temp_name}; print "$result\n"; } } __DATA__ abc,Alan,Bloggs,06/11/2009,11/30/2011,morefields,... cde,David,Smith,06/08/2009,09/30/2012,morefields,... abc,Rosario,Anotherone,06/05/2009,11/30/2011,morefields,... acd,Angela,Madeupname,06/11/2009,07/31/2010,morefields,... cde,Ugochukwu,Smith,06/01/2009,10/31/2012,morefields,... tla,Julie,Schmidt,05/01/2009,09/30/2012,morefields,... tl,Waseem,Alder,06/11/2009,11/30/2011,morefields,...
  • Comment on Re: nested loops to compare 2 files is only looping a limited number of times.
  • Download Code

Replies are listed 'Best First'.
Re^2: nested loops to compare 2 files is only looping a limited number of times.
by stevemayes (Scribe) on Jun 23, 2009 at 18:09 UTC

    It's not moot. I'm a beginner, and I specifically asked for comments on the approach as well as alternatives.

    I am looking at your code and, if I'm honest, going, huh? at certain points, but I guess I'm just going to run it, stick in some evals or possibly learn Data::Dumper and try and work it out.

    so a genuine thank you for taking the time to write out an alternative approach

    Steve

    (and in response to Bloodnok's sig - I firmly believe that initiate vastly overstates my abilities)