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

Hello monks,
I'm trying to determine the count for duplicate array elements for the "OID_NAME" from the following dump:
$VAR1 = { 'response_1.3.6.1.2.1.2.2.1.12.27' => { 'Error_Status' => 'No error', 'Packets' => 1, 'OID_NAME' => [ [ '1.3.6.1.2.1.2.2.1.11.27', 'ifInUcastPkts.27' ], [ '1.3.6.1.2.1.2.2.1.15.27', 'ifInUnknownProtos.27' ], [ '1.3.6.1.2.1.2.2.1.14.27', 'ifInErrors.27' ], [ '1.3.6.1.2.1.2.2.1.13.27', 'ifInDiscards.27' ], [ '1.3.6.1.2.1.2.2.1.15.27', 'ifInUnknownProtos.27' ], [ '1.3.6.1.2.1.2.2.1.14.27', 'ifInErrors.27' ], [ '1.3.6.1.2.1.2.2.1.14.27', 'ifInErrors.27' ], ] }, 'request_1.3.6.1.2.1.2.2.1.12.27' => {
I'm using the following snippet without any luck
if ({$key_hash{$current_key}{OID_NAME}}->[0]->[1]) { print "Duplicate Found\n"; } else { push @{$key_hash{$current_key}{OID_NAME}}, [$oid, $name]; }

Replies are listed 'Best First'.
Re: Determining duplicate array elements
by pg (Canon) on Mar 24, 2003 at 16:38 UTC
    Be careful, this piece of code is untested, due to lack of testing data. If there is any gap, just ask back, we will help.

    replace $var1 with your real variable name.

    #!/usr/bin/perl use strict; my $hash; foreach my $pair (@{$var1->{"OID_NAME"}}) { $hash->{$pair->[0]} ++; }
Re: Determining duplicate array elements
by dragonchild (Archbishop) on Mar 24, 2003 at 15:56 UTC
    Use a hash. For example:
    my %x; $x{$_}++ for @{$key_hash{$current_key}{OID_NAME}}; print "$_ has $x{$_} entries\n" for sort keys %x;

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.