Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Complicated Nested Data Structures

by elusion (Curate)
on Aug 09, 2000 at 05:42 UTC ( #26922=perlquestion: print w/replies, xml ) Need Help??

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

ok, perl monks, I think I'm a little over my head this time. I'm trying to print what I think is an array of a hash of a reference to an array. I'm calling one of Net::Pop3's methods (get) which get's a message and stores it as a reference to an array. This is the code @{$msgs[$command]{message}} = $pop->get($command); now how do I explain that and how do I print that? Thanx for your help,

- p u n k k i d
"Reality is merely an illusion, albeit a very persistent one." -Albert Einstein

Replies are listed 'Best First'.
Re: Complicated Nested Data Structures
by jlp (Friar) on Aug 09, 2000 at 05:58 UTC
    I'm not sure I understand the question. Do you want to print the datastructure itself, or the data it contains? If you want to print a representation of the datastructure, use Data::Dumper:

    use Data::Dumper; my $structure = [ 'complex', { data => 'structure' } ]; print Dumper($structure);
      Sorry, I tend to think a little different than most people and assume the wrong things. That line of code assigns a reference to an array which contains an email message. I want to be able to print that. I hope that makes more sense.

      - p u n k k i d
      "Reality is merely an illusion, albeit a very persistent one." -Albert Einstein

        Gotcha. No problem :) If all you want to do is print the contents of an array reference, just do:

        print @{ $arrayref };

        So, in your example, all you should have to do is:

        print @{ $msgs[$command]->{message} }

        assuming I understand the way your datastructure is setup. Hope that helps.

Re: Complicated Nested Data Structures
by btrott (Parson) on Aug 09, 2000 at 06:30 UTC
    The get method returns an array *reference*, not an actual array. So your statement should be
    $msgs[$command]{message} = $pop->get($command);
    That will store the array reference in
    $msgs[$command]{message}
    To dump our your @msgs array--to get a sense of what it looks like, visually--you can use Data::Dumper, as jlp suggested:
    print Dumper \@msgs;
      Thanx. That worked beautifully, once I realized that in order to print it I need to say print @{msgs[$command]{message}}; I appreciate your help.

      - p u n k k i d
      "Reality is merely an illusion, albeit a very persistent one." -Albert Einstein

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://26922]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2023-09-22 19:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?