Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re: Re: recomendations needed for type of data structure

by integral (Hermit)
on Feb 17, 2003 at 20:26 UTC ( #236102=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: recomendations needed for type of data structure
in thread recomendations needed for type of data structure

This is because the array of traps is stored as a reference to an anonymous array in one of the keys (TRAP_LIST) of the anonymous hash in the TRAPS key of the %$hash. This means that when you try to print the keys and values of the %{$hash->{TRAPS}} hash, you get the stringified array reference. To solve this you could add a special case to the output loop which prints the contents of the array.

# this handles ARRAYs and HASHes # you may want to use Data::Dumper for debugging however # the final code for processing the data structure will # also be less generic than this code. if (ref $value eq 'ARRAY') { print "$key => (@$value)\n"; } elsif (ref $value eq 'HASH') { print "$key => (%$value)\n"; } else print "$key => $value\n"; }

--
integral, resident of freenode's #perl


Comment on Re: Re: Re: recomendations needed for type of data structure
Select or Download Code
Re: Re: Re: Re: recomendations needed for type of data structure
by Anonymous Monk on Feb 17, 2003 at 21:09 UTC
    Thank you Integral
    One last question,

    What would the syntax be if I wanted to simply print out?:

    Varbind: 1.3.6.1.2.1.2.2.1.1
    Thanks again, I'm slowly piecing this all together.
      Well assuming that $key = 'Varbind' and that $value is an array ref containing each part of the id, then you can use join:
      print "$key: ".join('.',@$value)."\n";

      When you use an array in a string (like "@a"), perl translates this internally into join($", @a), one can see this if you turn perl's bytecode back into source code using B::Deparse.

      --
      integral, resident of freenode's #perl
      
Re: Re: Re: Re: recomendations needed for type of data structure
by steves (Curate) on Feb 17, 2003 at 21:49 UTC

    Exactly ... that's part of what needs finishing. My laziness got the best of my hubris. 8-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://236102]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2015-07-07 04:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (87 votes), past polls