in reply to Re: How to Print Return Data from Subroutine
in thread How to Print Return Data from Subroutine

Thank you so much. If you can be a little bit more patient with me, how do I print them in the following format without using data dumper?
print $ref->{c}; # This gave me 55 which is what I want. foreach my $i ($ref->@a) { print $i; # I want to see the content of the array, this + gave me an error. } foreach my $i ($ref->%b} { print $i; # I want to see the content of the hash. }

Replies are listed 'Best First'.
Re^3: How to Print Return Data from Subroutine
by kyle (Abbot) on Aug 24, 2008 at 03:38 UTC
    foreach my $i ($ref->@a) { print $i; # I want to see the content of the array, this + gave me an error. }

    I can't tell if this is what you mean or not:

    foreach my $i ( @{$ref}{@a} ) { print $i; }

    Or maybe it's simpler than that:

    foreach my $i ( @a ) { print $i; }
Re^3: How to Print Return Data from Subroutine
by betterworld (Curate) on Aug 24, 2008 at 10:58 UTC
    foreach my $i ($ref->%b} { print $i; # I want to see the content of the hash. }

    "b" in the hash is now only a hash key, and therefore you cannot put a "%" sign before "b", but you need a %{...} to dereference the hash. This will work:

    foreach my $i ( %{ $ref->{b} } ) { print $i; # I want to see the content of the hash. }

    (It will print keys and values by turns.)