7 use Text::Balanced qw/extract_bracketed/;
9 open my $hash_t, '<', 't/20-hash.t';
10 open my $array_t, '>', 't/30-array.t';
11 open my $array_fast_t, '>', 't/31-array-fast.t';
13 sub num { ord($_[0]) - ord('a') }
17 return $h unless $h and ref $h eq 'HASH';
20 $array[num($_)] = hash2array($h->{$_});
27 return 'undef' unless defined $a;
28 return $a unless ref $a;
29 die "Invalid argument" unless ref $a eq 'ARRAY';
30 return '[ ' . join(', ', map dump_array($_), @$a) . ' ]';
33 sub extract ($) { extract_bracketed $_[0], '{', qr/.*?(?<!\\)(?:\\\\)*(?={)/ }
40 print $array_fast_t $_;
44 print $array_fast_t $_;
46 for my $file ([ 1, $array_t ], [ 0, $array_fast_t ]) {
48 s!(\ba\b)?(\s*)HASH\b!($1 ? 'an': '') . "$2ARRAY"!eg;
49 s!->{([a-z])}!my $n = num($1); '->[' . ($file->[0] ? "\$N[$n]" : $n) .']'!eg;
53 my ($bracket, $prefix);
54 while (do { ($bracket, $suffix, $prefix) = extract($suffix); $bracket }) {
55 $buf .= $prefix . dump_array(hash2array(eval $bracket));
60 print { $file->[1] } "$buf\n";