in reply to Re^4: Matching hashes
in thread Matching hashes
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
|
|---|