Perlseeker_1 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Experts,

I am using multidimensional hashes for the first time, and i have come across some issues, please suggest me some ideas to resolve

$VAR1 = 'FILE_A'; $VAR2 = { 'CHECK_1' => { 'JAPAN' => { 'A' => 1 }, 'CHINA' => { 'B' => 2 }, 'MALYA' => { 'C' => 1 }, 'EUROP' => { 'D' => 1 } } }; $VAR3 = 'FILE_B'; $VAR4 = { 'CHECK_2' => { 'JAPAN' => { 'A' => 1 }, 'CHINA' => { 'B' => 1 }, 'EUROPE' => { 'C' => 1 } }

Output what i got

FILE_NAME A B C D CHECK 2 3 2 1

Output what i am expeting

FILE_NAME A B C D CHECK 1 2 1 1

I am reading the data from two files and checking if data exist in other file, if exists then exclude those records while writing final output

Replies are listed 'Best First'.
Re: How to use multidimensional hashes
by toolic (Bishop) on Jan 31, 2014 at 14:34 UTC
Re: How to use multidimensional hashes
by SimonPratt (Friar) on Jan 31, 2014 at 16:11 UTC

    Wow, you really need to provide some code, showing what you are doing

    I'm guessing here, but something along the lines of the following will do what I think you want:

    print $VAR4{CHECK_2}{JAPAN}{A} unless exists $VAR2{CHECK_1}{JAPAN}{A};

Re: How to use multidimensional hashes
by x-lours (Sexton) on Jan 31, 2014 at 14:47 UTC
    which code did you use to obtain this ?

      I have two input files and I need to read each record from the file and need to count the number of A's, B's etc and if it repeated in other file, don't take the count and any help on this please

      FILE_A 01|JAPAN|A| 01|CHINA|B| 01|CHINA|B| 01|MALY|C| 01|EUROPE|D|
      FILE_A 01|JAPAN|A| 01|CHINA|B| 01|MALY|C| <p>output what i am expecting is</p> <code> FILE_NAME A B C D CHECK 1 2 1 1

        if you count/sum only the A B C D ... it is normal to get

        FILE_NAME A B C D

        CHECK 2 3 2 1

        JAPAN A is in FILE_A and FILE_B so 2 times

        CHINA B is in FILE_A (twice) and FILE_B so 3 times

        MALY C is in FILE_A and FILE_B so 2 times

        if you don't want to count/sum after the first time, tou have to test the exists before.