Hi,

Thanks for your help, it seems to be doing the job and in a fraction of the
time. You are right about the keys and values being the same- that was an
error, the hash is arranged as you have said ( '12345' => '67890'). There
seems to be a slight error, the following error messages appear on numerous
occasions, line 83 is the print statement, also some of the values in the
outfile have no keys? I cannot see why it is giving the error messages:

Use of uninitialized value in hash element at prepare.pl 83.
Use of uninitialized value in concatenation (.) or string at prepare.pl
line 83.

   foreach my $keyA (keys hashA) {
        my $keyB = $hashC{$keyA};
      print "$keyA\n$hashA{keyA}\n\n$keyB\n$hashB{keyB}"
    }



=======================
Rob Dixon wrote:

> 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]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to