Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Complicated Nested Data Structures

by elusion (Curate)
on Aug 09, 2000 at 05:42 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (1)
As of 2024-07-21 23:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.