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

前端 未结 11 1538
借酒劲吻你
借酒劲吻你 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条回答
  •  醉酒成梦
    2020-12-22 16:21

    Looping:

    foreach(keys %my_hash) { print "$_ / $my_hash{$_}\n"; }
    

    Functional

    map {print "$_ / $my_hash{$_}\n"; } keys %my_hash;
    

    But for sheer elegance, I'd have to choose wrang-wrang's. For my own code, I'd choose my foreach. Or tetro's Dumper use.

提交回复
热议问题