Aimal Pashtoonmal wrote:
> Hello,
>
> I am about to finish a perl script but it takes very long to run as I
> am using three foreach loops one after the other. I have three files
> with data passed into hashes:
>
> FileA keyA = 12345
> valueA = abcdefgh
>
> FileB keyB = 67890
> valueB = ijklmno
>
> FileC keyC = 12345:67890 (key from 1st file)
> valueC = 12345:67890 (key from 2nd file)
Are you saying that you have already read your data into hashes?
FileC looks a bit strange. Relating
'12345:67890' => '12345:67890'
is not useful at all - all of the information is in the key (or the
value, which is the same!). What you need is a hash like:
'12345' => '67890'
> I am trying to print keyA followed by valueA and then find the
> corresponding partner in FileB using FileC and then to print that keyB
> and its valueB into a file. I have 10000 key-value pairs in each hash
> FileA and FileB so in the end I will have 10000 files, so that output
> file1 (name =keyA:keyB ) will look like:
>
> FileA keyA = 12345
> valueA = abcdefgh
>
> FileB keyB = 67890
> valueB = ijklmno
>
>
> At the moment my syntax towards the end is a bit like:
>
> foreach $keyC (keys hashC) {
> foreach $keyB (keys hashC) {
> foreach $keyA (keys hashA) {
> if ($keyC =~ $keyB && $keyC =~ $keyA ) {
> print "keyA\n$hashA{keyA}\n\n$keyB\n$hashB{keyB"
> }
> }
> }
>
> As you would expect there are 10000 keys in each of the three files so
> thats e+12 searches and it is taking very long. Does any one know a
> quicker way of doing this.
With the FileC data as I showed above, you could write:
foreach my $keyA (keys hashA) {
my $keyB = $hashC{$keyA};
print "$keyA\n$hashA{keyA}\n\n$keyB\n$hashB{keyB}"
}
but I'm still not clear where you data is and how it's structured.
Cheers,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]