$/ = $\;
@tests = split /\*{30}/, <DATA>;
for (@tests){
/{(.*)}(.*)/ms;
($kson, $table) = ("($1)", $2);
/
"=>"
/xmsge;
$table =~ s/^\s+//ms;
@table = split /\n/, $table;
@plus = ();
push @plus, pos $table[0] while $table[0] =~ m/\+/g;
@table = grep m/^\|/m, @table;
for $i (0 .. @table-1){
for $j (0 .. @plus -2){
$T[$i][$j] = substr $table[$i], $plus[$j], $plus[$j+1] - $plus[$j] - 1; ^ ( \
s* Value
: ( [.\w ]*? ) \
s* ) $
/
$match = $1,
$keys = $2,
$keys
:
$match
/xgmse
}
}
@jmax = ();
for $j (0 .. @plus -2){
$max = 0;
for $i (0 .. @table-1){
$max < $len and $max = $len;
}
for $i (0 .. @table-1){
$T[$i][$j] .= ' ' x
($max - length $T[$i][$j]); }
}
'',
( map "$_\n", map { join '|', '', @{ $T[$_] }, '' } 0 .. @table-1 ), '',
);
}
__DATA__
{}
++-------------+-------------------------+----------------------+--+
|| | Value: | Value:. | |
++-------------+-------------------------+----------------------+--+
******************************
{
}
++-------------+-------------------------+----------------------+--+
|| |Value: |Value:. | |
++-------------+-------------------------+----------------------+--+
******************************
{ "":"a b"
}
+-------------+-------------------------+----------------+---------+
| Value:|Value: |Value:. | Value:.|
+-------------+-------------------------+----------------+---------+
******************************
{ "b c":"a b"
}
+-------------+-------------------------+----------------+----------+
| Value:b c | Value:b c|Value: b c |Value:.b c|
+-------------+-------------------------+----------------+----------+
******************************
{ "" :
"" }
+-------------+-------------------------+----------------+----------+
| Value: | Value:|Value: |Value:. |
+-------------+-------------------------+----------------+----------+
| Value : | value:|Value: .| Value:.|
+-------------+-------------------------+----------------+----------+
******************************
{ "c d" :
" fg " , "c" : "f","d" : ": ."
}
+-------------+-------------------------+----------------+----------+
| Value:c d| Value:c |Value:d |Value:. |
+-------------+-------------------------+----------------+----------+
| Value:d. | Value:.d |Value: d | Value:d.c|
+-------------+-------------------------+----------------+----------+
******************************
{ "fg" : {}, "12 34" :
"..." , "c" : { "d" : "cd", "e" : { } }
}
+-------------+-------------------------+----------------+----------+
| Value:fg | Value:12 34 |Value:c |Value:fg. |
+-------------+-------------------------+----------------+----------+
| Value:c.d | Value:d |Value:c.e | Value:e |
+-------------+-------------------------+----------------+----------+
JC8gPSAkXDsKCkB0ZXN0cyA9IHNwbGl0IC9cKnszMH0vLCA8REFUQT47Cgpmb3IgKEB0ZXN0cyl7CgoveyguKil9KC4qKS9tczsKCigka3NvbiwgJHRhYmxlKSA9ICgiKCQxKSIsICQyKTsKCiRrc29uID1+IHMvCgkiLio/IiBccyogXEsgOgovCgkiPT4iCi94bXNnZTsKCiVoID0gZXZhbCAka3NvbjsKCiR0YWJsZSA9fiBzL15ccysvL21zOwoKQHRhYmxlID0gc3BsaXQgL1xuLywgJHRhYmxlOwoKQHBsdXMgPSAoKTsKcHVzaCBAcGx1cywgcG9zICR0YWJsZVswXSB3aGlsZSAkdGFibGVbMF0gPX4gbS9cKy9nOwoKQHRhYmxlID0gZ3JlcCBtL15cfC9tLCBAdGFibGU7Cgpmb3IgJGkgKDAgLi4gQHRhYmxlLTEpewoJZm9yICRqICgwIC4uIEBwbHVzIC0yKXsKCQkkVFskaV1bJGpdID0gc3Vic3RyICR0YWJsZVskaV0sICRwbHVzWyRqXSwgJHBsdXNbJGorMV0gLSAkcGx1c1skal0gLSAxOwoJCSRUWyRpXVskal0gPX4gcy8KCQkJXiAoIFxzKiBWYWx1ZTogKCBbLlx3IF0qPyApIFxzKiApICQKCQkvCgkJCSRtYXRjaCA9ICQxLAoJCQkka2V5cyA9ICQyLAoJCQlAa2V5cyA9IChzcGxpdCBtIVwuISwgIiRrZXlzLkEiKSwKCQkJcG9wIEBrZXlzLAoJCQkkc3BhY2VfZmFpbCA9IChncmVwIG0hXiB8ICQhLCBAa2V5cyksCgkJCSRrZXlzID0gZXZhbCAnJGgnIC4gKGpvaW4gJycsIG1hcCBxcVt7IiRfIn1dLCBAa2V5cyksCgkJCWRlZmluZWQgJGtleXMgJiYgISAocm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