Here i am once again with a desperate attempt to sort my way through weird system configs with Perl.
At this point i have a hash where the values are a list of references to arrays. It's not really interesting what's inside, but maybe that structure is not the best one for my problem, or maybe you're just curious, so : the keys are unique adresses and each list is a bunch of devices mapped to it. I need to make sure that every device is in every list, that is that all these list are equals.
It should be easy, but i find myself doing this in an ugly way.
Here's what my hash looks like :
It could be that there is only one key, or more than 2. Also, in the end, i'm looping through a structure to build this hash, but let's forget that.$VAR1 = { 'Ad1' => [ '0A78', '0A9E', '0AB9', '0AC0', ], 'Ad2' => [ '0A78', '0A9E', '0AB9', '0AC0', + ] };
Here's what i do :
#!perl use strict ; use warnings ; my $refcomp= { 'Ad1' => [ '0A78', '0A9E', '0AB9', '0AC0', ], 'Ad2' => [ '0A78', '0A9E', '0AB9', '0AC0', + ] }; my %comp =%$refcomp ; # my code uses a hash, not a ref, so ... my %found ; if (scalar keys %comp > 1 ) { for my $adress (keys %comp) { for my $dev ( @{$comp{$adress}} ) { $found{$dev}++ } } } my %uniq ; for my $it (values %found) { $uniq{$it}++ } ; if ( scalar keys %uniq > 1 ) { print "ERR : Problem in device list\n" ; }
Anyone has a nicer way ? Thanks !
zlr
In reply to Looping through arrays : are they equal ? by ZlR
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |