How can I print the contents of a hash in Perl?

前端 未结 11 1507
借酒劲吻你
借酒劲吻你 2020-12-22 15:52

I keep printing my hash as # of buckets / # allocated. How do I print the contents of my hash?

Without using a while loop would be most preferable (for

11条回答
  •  梦毁少年i
    2020-12-22 16:11

    The easiest way in my experiences is to just use Dumpvalue.

    use Dumpvalue;
    ...
    my %hash = { key => "value", foo => "bar" };
    my $dumper = new DumpValue();
    $dumper->dumpValue(\%hash);
    

    Works like a charm and you don't have to worry about formatting the hash, as it outputs it like the Perl debugger does (great for debugging). Plus, Dumpvalue is included with the stock set of Perl modules, so you don't have to mess with CPAN if you're behind some kind of draconian proxy (like I am at work).

提交回复
热议问题