in reply to %hash print output formatting question

It's right in the docs :)

"If you evaluate a hash in scalar context, it returns false if the hash is empty. If there are any key/value pairs, it returns true; more precisely, the value returned is a string consisting of the number of used buckets and the number of allocated buckets, separated by a slash."
  • Comment on Re: %hash print output formatting question

Replies are listed 'Best First'.
Re^2: %hash print output formatting question
by toolic (Bishop) on Oct 27, 2010 at 21:02 UTC
    The OP can avoid evaluating the hash in scalar context by changing the dots to commas in the print statement:
    sub print_formatted { print "print \%hash with other text:\n"; print "\%hash: " , %hash , "\n\n"; }

    For quick dumping of hashes (and arrays, and references, etc.), see also Data::Dumper.

      makes perfect sense... Thanks for the tip on using commas instead!!

      fyi - I'm a big fan of Data::Dumper, but in this case I was being a bit lazy...

      Thanks again!
      Life is short, but it's wide -- Chuck Pyle
Re^2: %hash print output formatting question
by duggles (Acolyte) on Oct 27, 2010 at 22:30 UTC

    makes perfect sense... I get a little frustrated trying to find things in the docs - I do remember (a long time ago) reading something about the buckets though....

    I appreciate you pointing me in the right direction!

    Life is short, but it's wide -- Chuck Pyle