Hello Perl Pros,

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 :

$VAR1 = { 'Ad1' => [ '0A78', '0A9E', '0AB9', '0AC0', ], 'Ad2' => [ '0A78', '0A9E', '0AB9', '0AC0', + ] };
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.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.