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

Hello again,
I'm trying to retrieve just a list of nodes from the following data dump:

i.e.  @array = qw(pnnixNodeCfgParentNodeIndex  pnnixRouteNodeFwdMetric1 pnnixRouteNodeFwdMetric2);
$VAR1 = bless( { 'tree' => { 'pnnixIAdjGroup' => { '1' => 'pnnixNumIAdj', '2' => 'pnnixIAdjTable' }, 'pnnixLinkEntry' => { '1' => 'pnnixLinkPortId', '2' => 'pnnixLinkType', '3' => 'pnnixLinkVersion', '4' => 'pnnixLinkHelloState', '10' => 'pnnixLinkCommonPeerGroupId', '11' => 'pnnixLinkIfIndex', '14' => 'pnnixLinkXmtHellos', '8' => 'pnnixLinkUpnodeId', '9' => 'pnnixLinkUpnodeAtmAddress' }, 'make_dump' => 1, 'use_dump' => 1, 'nodes' => { 'pnnixNodeCfgParentNodeIndex' => { 'status' => 'mandatory', 'description' => '"The local node index used to identify the nod +e that will represent this peer group at the next higher level of hierarchy, if this node becomes peer group leader. The value 0 indicates that there is no parent node."', 'syntax' => { 'type' => 'PnnixNodeIndex' }, 'oid' => [ 'pnnixNodePglEntry', '2' ], 'access' => 'read-write', 'type' => 'OBJECT-TYPE' }, 'pnnixRouteNodeFwdMetric1' => { 'status' => 'mandatory', 'description' => '"An alternate routing parameter for the forwar +d direction of this route. For information learned from PNNI nodes, this is the maximum possible cell rate (in cells per second) for the forward direction of the route. If this parameter is not used, its value should be set to 0xFFFFFFFF."', 'syntax' => { 'type' => 'Gauge' }, 'oid' => [ 'pnnixRouteNodeEntry', '10' ], 'access' => 'read-write', 'type' => 'OBJECT-TYPE' }, 'pnnixRouteNodeFwdMetric2' => { 'status' => 'mandatory', 'description' => '"An alternate routing parameter for the forwar +d direction of this route. For information learned from PNNI nodes, this is the Available cell rate (in cells per second) for the forward direction of the route. Further information on available bandwidth may be obtainable by reference to the nodal advertisements of the nodes in the path. If this parameter is not used, its value should be set to 0xFFFFFFFF."', 'syntax' => { 'type' => 'Gauge' }, 'oid' => [ 'pnnixRouteNodeEntry', '11' ], 'access' => 'read-write', 'type' => 'OBJECT-TYPE' }, 'pnnixRouteNodeFwdMetric3' => { 'status' => 'mandatory', 'description' => '"An alternate routing parameter for the forwar +d direction of this route. For information learned from PNNI nodes, this is the cumulative Maximum Cell Transfer Delay (in microseconds) for the forward direction of the route. If this parameter is not used, its value should be set to 0xFFFFFFFF."', 'syntax' => { 'type' => 'Gauge' }, 'oid' => [ 'pnnixRouteNodeEntry', '12' ], 'access' => 'read-write', 'type' => 'OBJECT-TYPE' },
This is the code I'm using, but itdoesn't seem to be working
my $name = $mib->compile($mib_name); print Dumper($name); my @trap = (); foreach ($name) { push @trap, $name->{'nodes'}->{$_}; }
Any ideas why @trap isn't getting populated?

update (broquaint): added <readmore> tag

Replies are listed 'Best First'.
Re: Array from Data Dump
by tall_man (Parson) on Mar 03, 2003 at 14:58 UTC
    There's something very odd here. You are using $name for a reference variable and also for the variable in your foreach loop. The $_ is just going to get a stringified name like HASH(0x80579ec).

    What you need is to loop over the keys of $name->{'nodes'}, as in:

    foreach (keys %{$name->{nodes}}) { push @trap,$name->{'nodes'}->{$_}; }
      foreach (keys %{$name->{nodes}}) { push @trap,$name->{'nodes'}->{$_}; }
      Is returning a hash ref:
      HASH(0x2138d1c) HASH(0x1fff6a8) HASH(0x1fff744) HASH(0x1fff7e0) HASH(0 +x1fff87c) HASH(0x214fc78) HASH(0x1ffd238) HASH(0x1fe336c) HASH(0x1ffd2d4) HASH(0x1ffd370) HASH(0 +x1ffd40c) HASH(0x215c52c)
        Well, of course it does if you do something like this after the loop is done:
        print join(" ",@trap),"\n";
        You said you wanted to extract your nodes, and that's what you get -- hash references to the nodes stored in @trap. If you print them, you'll get stringified references. You can use Data::Dumper on them, or dereference them to process their fields, but just printing them won't work.

        Update: Did you just want the list of node names? Then do:

        my @trap = keys %{$name->{nodes}};