Module to print hash?

P

Peng Yu

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";
}
 
P

Peter J. Holzer

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
 
J

Justin C

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.
 
C

Charlton Wilbur

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top