Another idea for you... Sometimes Hash of Array is useful.
#!/usr/bin/perl use strict; use warnings; my %hash; while (my $line = <DATA>) { next if $line =~ /^\s*$/; #skip blanks chomp $line; my ($value, $key) = split ':',$line,2; push @{$hash{$key}},$value; } foreach my $key (sort keys %hash) { print "$key => @{$hash{$key}} ERROR Single Node!\n" if @{$hash{$ke +y}}<2; } =prints vg3:38 => node1 ERROR Single Node! vg3:40 => node2 ERROR Single Node! =cut __DATA__ node1:vg1:36 node2:vg1:36 node1:vg2:37 node2:vg2:37 node1:vg3:38 node2:vg3:40
Update: I did a very poor job of naming in the above example. Normally I would call a hash by the names of the values it contains...instead of just %hash, %nodes would be better. Of course some descriptive name for "vg1:36" is far better that just "$key". With the good names, foreach my $machine_port (sort keys %nodes) is much more readable. I have no idea whether "machine_port" is right or not because I have no idea what "vg1:36" means in the real world.

HoA can be useful because multidimensional hashes require a loop for each dimension in order to traverse the entire HoHoH..


In reply to Re: Compare the values in the hash by Marshall
in thread Compare the values in the hash by perl_5eeker

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.