X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=samples%2Fhash2array.pl;h=e70b69be8ea90e83c558a527dcc862c8a0beba67;hb=68e31f8ce73ddedf82977b4e05ec550c1cfe5688;hp=8b3419d1139fbdbb68f742470b85125bbc8aec40;hpb=167a7d1ceb42868217cdc88690f5d565527b3d6c;p=perl%2Fmodules%2Fautovivification.git diff --git a/samples/hash2array.pl b/samples/hash2array.pl index 8b3419d..e70b69b 100644 --- a/samples/hash2array.pl +++ b/samples/hash2array.pl @@ -10,7 +10,10 @@ open my $hash_t, '<', 't/20-hash.t'; open my $array_t, '>', 't/30-array.t'; open my $array_fast_t, '>', 't/31-array-fast.t'; -sub num { ord($_[0]) - ord('a') } +sub num { + my ($char) = $_[0] =~ /['"]?([a-z])['"]?/; + return ord($char) - ord('a') +} sub hash2array { my ($h) = @_; @@ -46,7 +49,12 @@ while (<$hash_t>) { for my $file ([ 1, $array_t ], [ 0, $array_fast_t ]) { local $_ = $_; s!(\ba\b)?(\s*)HASH\b!($1 ? 'an': '') . "$2ARRAY"!eg; - s!->{([a-z])}!my $n = num($1); '->[' . ($file->[0] ? "\$N[$n]" : $n) .']'!eg; + s{ + {\s*(['"]?[a-z]['"]?(?:\s*,\s*['"]?[a-z]['"]?)*)\s*} + }{ + '[' . join(', ', map { my $n = num($_); $file->[0] ? "\$N[$n]" : $n } + split /\s*,\s*/, $1) . ']' + }gex; s!%(\{?)\$!\@$1\$!g; my $buf; my $suffix = $_;