in reply to Re: How to check that keys in two hashes match and get the corresponding values
in thread How to check that keys in two hashes match and get the corresponding values

Thanks ever so much for your help Roboticus. I have tried this out and this is now matching up these key values perfectly. I just have one question though. Maybe it because I dont fully understand all of your code but when I run this its seems to print out lines more than once. This seems to happen when either %filer_device is a hash or %filer_volume is a hash or both are hashes. So for example in the following section:

"rtsys_mpt": { "%export_name": "/bb/rtsys", "%filer_device": { "@west": "nydevnfs_rtsysgit", "@ridge": "njdevnfs_rtsysgit" }, "%filer_volume": "/vol/rtsysgit" }

When I run your code on this and just purely print out the volume and device values i get the lines duplicated like so:

njdevnfs_rtsysgit = /vol/rtsysgit nydevnfs_rtsysgit = /vol/rtsysgit njdevnfs_rtsysgit = /vol/rtsysgit nydevnfs_rtsysgit = /vol/rtsysgit

All that I need is this:

njdevnfs_rtsysgit = /vol/rtsysgit nydevnfs_rtsysgit = /vol/rtsysgit

But for some reason its duplicated? I am not too sure why? and in this section where %filer_device and %filer_volume are both hashes it outputs the same lines 3 times:

"build18_mpt": { "%export_name": "/bb/mobile", "%filer_device": { "@west": "nydevnfs_mob_build", "@ridge": "rnap2113-s" }, "%filer_volume": { "@west": "/vol/mob_build", "@ridge": "/vol/mob_build_c" } },
nydevnfs_mob_build = /vol/mob_build rnap2113-s = /vol/mob_build_c nydevnfs_mob_build = /vol/mob_build rnap2113-s = /vol/mob_build_c nydevnfs_mob_build = /vol/mob_build rnap2113-s = /vol/mob_build_c

All i need is the first two lines. The others are duplicates:

nydevnfs_mob_build = /vol/mob_build rnap2113-s = /vol/mob_build_c

Do you know why this is happening please?

Replies are listed 'Best First'.
Re^3: How to check that keys in two hashes match and get the corresponding values
by roboticus (Chancellor) on Apr 15, 2013 at 12:43 UTC

    NewLondonPerl1:

    I'm not seeing the problem, so I guess you made some change that you haven't mentioned. Without making any changes other than adding your new test case:

    . . . snip . . . my $nfshashofhashes = { "rtsys_mpt" => { '%export_name' => '/bb/rtsys', '%filer_device' => { '@west' => 'nydevnfs_rtsysgit', '@ridge' => 'njdevnfs_rtsysgit', }, '%filer_volume' => '/vol/rtsysgit', }, "bigstorderv_mpt" => { . . . snip . . .

    I get the following, which seems to be what you're wanting:

    $ perl 1028644.pl bigstorderv_mpt nydevnfs_derv /vol/derv /bb/big +stor/derv build11_mpt ???? /vol/sunbbsource_c /bb/sou +rce build11_mpt rnap7751-s ???? /bb/sou +rce build11_mpt ???? /vol/sunquirks /bb/sou +rce build11_mpt nydevnfs_sunbbsource /vol/sunbbsource /bb/sou +rce build10_mpt rnap7751-s /vol/sunbbsource_c /bb/sou +rce build10_mpt nydevnfs_sunbbsource /vol/sunbbsource /bb/sou +rce rtsys_mpt njdevnfs_rtsysgit /vol/rtsysgit /bb/rts +ys rtsys_mpt nydevnfs_rtsysgit /vol/rtsysgit /bb/rts +ys bigstormtg_mpt njdevnfs_mtge /vol/mtge /bb/big +stor/mtgmodel bigstormtg_mpt nydevnfs_mtge /vol/mtge /bb/big +stor/mtgmodel

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.