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

Monks
I'm sure this is easy but I would like your opinion on the best way of doing this.
I have three hash arrays
hash array %get_snmp has keys oids and values oid_values hash array %table_match has keys oids and values perf_equivs (oids the + same as in %get_snmp) hash array %get_perf has keys perf_equivs and values perf_values (perf +_equivs the same as in %table_match)
So for example I might have
%get_snmp = (status, 3, max_status, 7) %table_match = (status, pabStatus, max_status, pabMaxStatus) %get_perf = (pabStatus, 2, pabMaxStatus, 7)

I want to check if the perf_values are equal to their corresponding oid_values
So in the example above I want to check if the status value (3) is equal to the pabStatus value (2) and if the max_status value (7) is equal to the pabMaxStatus value (7)
Each of the hash arrays have over 50 elements each in them
Would references be the best way of doing this?
Thanks in advance
Bewildered

edited: Mon Jun 21 18:01:41 2004 by jeffa - code tags

Replies are listed 'Best First'.
Re: Matching values in Hash Arrays
by borisz (Canon) on Jun 19, 2004 at 13:42 UTC
    Heere is one way to do it.
    while ( my ( $k, $l ) = each %table_match ) { if ( $get_snmp{$k} != $get_perf{$l} ) { print "Different ( $k, $l )\n"; } else { print "ok ( $k, $l )\n"; } }
    Boris
Re: Matching values in Hash Arrays
by thor (Priest) on Jun 19, 2004 at 13:41 UTC
    Excuse me while I whip this out:
    #code that populates hashes here while( my ($oid, $perf) = each %table_match ) { if ( $get_snmp{$oid} == $get_perf{$perf} ) { print "OID: $oid and PERF: $perf are equal in value."; print "The value is $get_snmp{$oid}.\n"; } else { print "OID: $oid has value $get_snmp{$value} " print "while PERF: $perf has value $get_perf{$perf}." print " The two are not equal.\n"; } }
    Whether or not you use references shouldn't really effect the performance.

    thor

    Update:Fixed typo as per below.

      Small but important typo in there:

      if ( $get_snmp{$oid} == $get_perf{$oid} ) {

      should be

      if ( $get_snmp{$oid} == $get_perf{$perf} ) {
Re: Matching values in Hash Arrays
by Anonymous Monk on Jun 19, 2004 at 13:50 UTC
    Thats what I wanted. Thank you.