in reply to Re^2: My code sucks, please help me understand why.
in thread My code sucks, please help me understand why.

Since you can extract the IDs easily for each file, you can put the IDs from PIDS into a hash, and query that while iterating over FIDS:

my %ids; while (my $line = <PIDS>) { chomp $line; my (undef, $id) = split /\|/, $line; $ids{$id} = 1; } while (my $line = <FIDS>) { my ($id, $rest) = split /;/, $line, 2; if ($ids{$id}) { print "Found id '$id' in line $line"; } }
Perl 6 - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^4: My code sucks, please help me understand why.
by mirage4d (Novice) on Oct 15, 2009 at 15:32 UTC
    Thanks to both of you for your responses. I've implemented both solutions in addition to modifying the regex in my original script as recommended (thanks moritz), but still I get no matches. Really scratching my head over this one. I am beginning to wonder if there could be something amiss with my input that I am just not seeing. Any further suggestions would be much appreciated. Thanks again for your help.
      I don't understand what's wrong.

      It's clear that the example data you gave us doesn't give any matches, but if I modify it a bit I do get a match.

      Code:

      use strict; use warnings; use autodie; open my $pids, '<', 'pids'; my %ids; while (my $line = <$pids>) { chomp $line; my (undef, $id) = split /\|/, $line; $ids{$id} = 1; } close $pids; open my $fids, '<', 'fids'; while (my $line = <$fids>) { my ($id, $rest) = split /;/, $line, 2; if ($ids{$id}) { print "Found id '$id' in line $line"; } } close $fids;

      FIDS:

      810000001;08/17/1957 810000002;12/02/1975 810000003;12/22/1982 810000004;11/01/1967 810086196;02/07/1981 810000006;12/27/1967 810000007;05/09/1981 810000008;05/14/1976 810000009;10/24/1981 810000010;11/17/1943

      pids (unchanged):

      dn: cn=*****,ou=users,|810221480 dn: cn=*****,ou=users,|810039655 dn: cn=*****,ou=users,|810086196 dn: cn=*****,ou=users,|810008482 dn: cn=*****,ou=users,|810224329
      Perl 6 - links to (nearly) everything that is Perl 6.