From: Peng Yu on
Whenever, I want to print a hash for inspection of its content. I
could write the following while loop. But I feel this is a common task
and probably should be factor out into a module. Could you please let
me know if there is a well designed module that can print an
arbitrarily complex hash?

while (($key, $value) = each(%coins)){
print $key.", ".$value."\n";
}
From: Keith Keller on
On 2010-06-07, Peng Yu <pengyu.ut(a)gmail.com> wrote:
> Whenever, I want to print a hash for inspection of its content. I
> could write the following while loop. But I feel this is a common task
> and probably should be factor out into a module. Could you please let
> me know if there is a well designed module that can print an
> arbitrarily complex hash?

Use the Data::Dumper module. I am not sure if the following still
applies for your version of Perl, but read your Data::Dumper docs to be
sure:

BUGS
Due to limitations of Perl subroutine call semantics, you cannot
pass an array or hash. Prepend it with a "\" to pass its
reference instead. This will be remedied in time, now that Perl has
subroutine prototypes. For now, you need to use the extended usage
form, and prepend the name with a "*" to output it as a hash or
array.


--keith

--
kkeller-usenet(a)wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information

From: Peter J. Holzer on
On 2010-06-07 01:16, Keith Keller <kkeller-usenet(a)wombat.san-francisco.ca.us> wrote:
> BUGS
> Due to limitations of Perl subroutine call semantics, you cannot
> pass an array or hash. Prepend it with a "\" to pass its
> reference instead. This will be remedied in time, now that Perl has
> subroutine prototypes.

Perl has had prototypes for 15 years now, so I think it's a safe bet
that this "bug" will never be remedied.

hp
From: Justin C on
On 2010-06-07, Peng Yu <pengyu.ut(a)gmail.com> wrote:
> Whenever, I want to print a hash for inspection of its content. I
> could write the following while loop. But I feel this is a common task
> and probably should be factor out into a module. Could you please let
> me know if there is a well designed module that can print an
> arbitrarily complex hash?
>
> while (($key, $value) = each(%coins)){
> print $key.", ".$value."\n";
> }

Look for the module Data::Dumper. I believe that it's part of a standard
install.

Justin.

--
Justin C, by the sea.
From: Charlton Wilbur on
>>>>> "PY" == Peng Yu <pengyu.ut(a)gmail.com> writes:

PY> Whenever, I want to print a hash for inspection of its
PY> content. I could write the following while loop. But I feel this
PY> is a common task and probably should be factor out into a
PY> module. Could you please let me know if there is a well designed
PY> module that can print an arbitrarily complex hash?

You've been asking a lot of really fundamental questions.

Do you have a copy of _Programming Perl_ within arm's length? If not,
why not? Consulting that book *before* asking a question would probably
save you the time it takes to wait for a response, and would probably
save the people who read this newsgroup a lot of time.

Further, people only have so much patience to expend on other people's
questions. Would you rather get the help of the experts in this group
on basic questions that you could look up in _Programming Perl_, or
would you rather save their patience for when you have a *really*
difficult question?

Charlton


--
Charlton Wilbur
cwilbur(a)chromatico.net