Perl equiv to PHP print_r

Discussion in 'Perl Misc' started by Aidan, Mar 17, 2005.

  1. Aidan

    Aidan Guest

    Hi Perl Peoples,

    I'm quit new to perl, but have a pretty good knowledge of PHP. I'm playing
    around with a few packages, and I'm having a bit of trouble figuring out how
    to deal with hashes. In PHP, if I wanted to view the contents of $hash, all
    I needed to do would be dump it out by using:

    <? print_r($hash); ?>

    And I would get a nice heirachial display of the data contained within
    $hash. Is there an equivalent function in Perl? I'm sure there is, but
    after much googling, I still can't find what it is... can anyone here tell
    me what it is?

    TIA

    Aidan
    Aidan, Mar 17, 2005
    #1
    1. Advertising

  2. Aidan

    SMO Guest

    Aidan wrote:
    > Hi Perl Peoples,
    >
    > I'm quit new to perl, but have a pretty good knowledge of PHP. I'm playing
    > around with a few packages, and I'm having a bit of trouble figuring out how
    > to deal with hashes. In PHP, if I wanted to view the contents of $hash, all
    > I needed to do would be dump it out by using:
    >
    > <? print_r($hash); ?>
    >
    > And I would get a nice heirachial display of the data contained within
    > $hash. Is there an equivalent function in Perl? I'm sure there is, but
    > after much googling, I still can't find what it is... can anyone here tell
    > me what it is?
    >
    > TIA
    >
    > Aidan


    Have a look at Data::Dumper

    MS
    SMO, Mar 17, 2005
    #2
    1. Advertising

  3. Aidan

    Aidan Guest

    Thanks for the help guys... that's pretty much exactly what I wanted.

    Aidan

    "Jeff Boes" <> wrote in message
    news:1111095787.5145c5c1fa376c02cc145041eab58eba@teranews...
    > Aidan wrote:
    >> Hi Perl Peoples,
    >>
    >> I'm quit new to perl, but have a pretty good knowledge of PHP. I'm
    >> playing around with a few packages, and I'm having a bit of trouble
    >> figuring out how to deal with hashes. In PHP, if I wanted to view the
    >> contents of $hash, all I needed to do would be dump it out by using:
    >>
    >> <? print_r($hash); ?>
    >>
    >> And I would get a nice heirachial display of the data contained within
    >> $hash. Is there an equivalent function in Perl? I'm sure there is, but
    >> after much googling, I still can't find what it is... can anyone here
    >> tell me what it is?
    >>
    >> TIA
    >>
    >> Aidan
    >>

    >
    > There may be others, but the best I've found is:
    >
    > use strict;
    > use Data::Dumper;
    > my %hash = ('key1' => 'aaa',
    > 'key2' => { 'sub1' => '2bbb', 'sub2' => '2ccc' },
    > );
    > print Dumper( \%hash );
    >
    > which produces:
    >
    > $VAR1 = {
    > 'key2' => {
    > 'sub1' => '2bbb',
    > 'sub2' => '2ccc'
    > },
    > 'key1' => 'aaa'
    > };
    >
    >
    Aidan, Mar 18, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas Lindgaard

    print_r() or var_dump()

    Thomas Lindgaard, Jul 13, 2004, in forum: Python
    Replies:
    1
    Views:
    2,989
    Scott David Daniels
    Jul 15, 2004
  2. Rajive Narain
    Replies:
    0
    Views:
    1,471
    Rajive Narain
    Sep 18, 2009
  3. Namor
    Replies:
    7
    Views:
    108
    kwatch
    Mar 7, 2006
  4. Amittai Aviram

    Perl equiv to PHP file() ?

    Amittai Aviram, Aug 18, 2003, in forum: Perl Misc
    Replies:
    4
    Views:
    104
    Gunnar Hjalmarsson
    Aug 18, 2003
  5. Mark

    print_r()

    Mark, Nov 25, 2006, in forum: Perl Misc
    Replies:
    9
    Views:
    131
    Ted Zlatanov
    Nov 27, 2006
Loading...

Share This Page