Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Re: recomendations needed for type of data structure

by Anonymous Monk
on Feb 17, 2003 at 19:16 UTC ( [id://236081]=note: print w/replies, xml ) Need Help??


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

Thanks,
That' swhat I had in mind.
Just one question,
Do you know why the array for the Traps isn't printing out properly?
It's printing out the array reference instead
Thanks
  • Comment on Re: Re: recomendations needed for type of data structure

Replies are listed 'Best First'.
Re: Re: Re: recomendations needed for type of data structure
by integral (Hermit) on Feb 17, 2003 at 20:26 UTC
    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
    
      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
        

      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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://236081]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-26 08:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found