除了 Data::Dumper 以外,今天看到 Dumpvalue 這個也是內建的好用物件解析工具
使用方法:
#!/usr/bin/perl use 5.014; sub show { require Dumpvalue; state $prettily = Dumpvalue->new( compactDump => 1, veryCompact => 1); state $ugly = Dumpvalue->new(); say "-"x40; $prettily->dumpValue(\@_); say "-"x30; $ugly->dumpValue(\@_); say "-"x40; } my @AoA = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; my @AoH = ({1 => 2}, {2 => 3}, {3 => 4}); show(@AoA); show(@AoH);
output:
---------------------------------------- 0 ARRAY(0x9661910) 0 0..2 1 2 3 1 0..2 4 5 6 2 0..2 7 8 9 ------------------------------ 0 ARRAY(0x9661910) 0 ARRAY(0x9653068) 0 1 1 2 2 3 1 ARRAY(0x9653c58) 0 4 1 5 2 6 2 ARRAY(0x9653d18) 0 7 1 8 2 9 ---------------------------------------- ---------------------------------------- 0 1 => 2 1 2 => 3 2 3 => 4 ------------------------------ 0 HASH(0x9653c68) 1 => 2 1 HASH(0x9661ad0) 2 => 3 2 HASH(0x9661b10) 3 => 4 ----------------------------------------
Ref.
perldoc lol
http://perldoc.perl.org/Dumpvalue.html
No comments:
Post a Comment