Thread JSON UTF decode
(46 answers)
Opened by bianca at 2013-06-17 06:12
Zu jeder rekursiven Lösung gibt es eine Iterative. Also zu Lehrzwecken:
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 sub decode_obj { my ( $in ) = @_; my $out; my @stack=([$in,\$out]); while(@stack) { my ($old,$new) = @{ shift @stack }; if(ref $old eq 'ARRAY') { push(@stack,[ $old->[$_], \$$new->[$_] ]) for (0..$#$old); } elsif(ref $old eq 'HASH') { push(@stack,[ $old->{$_}, \$$new->{$_} ]) for (keys %$old); } else { $$new = Encode::encode( 'ISO-8859-15', $old ); } } return $out; } |