in reply to Re^3: Matching hashes
in thread Matching hashes

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^5: Matching hashes
by GrandFather (Saint) on Dec 05, 2007 at 19:46 UTC

    You will find that it helps a lot if you provide a code sample demonstrating your problem. I know what I mean. Why don't you? will give you some ideas for how to crunch your actual code down to a useful sample. However, consider:

    use strict; use warnings; my $info = <<INFO; PDB ID,SITE NUMBER,RESIDUE TYPE,CHAIN ID,RESIDUE NUMBER,CHEMICAL FUNCT +ION,EVIDENCE TYPE,LITERATURE ENTRY 102l,0,ASP,,20,S,PSIBLAST,206l 103l,0,ASP,,20,S,PSIBLAST,206l 104l,0,ASP,A,20,S,PSIBLAST,206l 104l,1,GLU,B,11,S,PSIBLAST,206l INFO my %lookup; <DATA>; # Skip the header line while (<DATA>) { my ($key) = split /,/, $_, 2; $lookup{$key} = 0; } open my $InFile, '<', \$info or die "Failed top open menory file: $!"; +; <$InFile>; # Skip Header while (<$InFile>) { my ($key) = split /,/, $_, 2; next unless exists $lookup{$key}; ++$lookup{$key}; } close $InFile; for my $key (sort keys %lookup) { print "$key: $lookup{$key}\n"; } __DATA__ PDB ID,SITE NUMBER,RESIDUE TYPE,CHAIN ID,RESIDUE NUMBER,CHEMICAL FUNCT +ION,EVIDENCE TYPE,LITERATURE ENTRY 102l,0,GLU,,11,S,PSIBLAST,206l 103l,0,GLU,,11,S,PSIBLAST,206l 104l,0,GLU,A,11,S,PSIBLAST,206l

    Prints:

    102l: 1 103l: 1 104l: 2

    Perl is environmentally friendly - it saves trees
Re^5: Matching hashes
by davido (Cardinal) on Dec 05, 2007 at 19:31 UTC

    Ah, it's been pointed out that I do in fact have a typo in my code:

    In line 9, change "$indices{$line}" to "$indices{$key}".

    I'll update my previous post to fix the code.


    Dave