in reply to Tk-reading-chinese-out-of-data
Update: actually, the eval approach does work -- for some reason, when DATA has CRLF line-breaks and my unix "chomp" leaves the "\r" behind, nothing works. After fixing it so that the "s/.../chr(hex())/eg" approach would work, I tried the eval approach again, and that worked too:sub define_codes_method2 { my $language; while (<DATA>) { s/\s+$//; # ("chomp" is too OS-dependent) next if !/\S/; if (/^%language=(.*)/) { $language = $1; } else { my ( $code, $descr ) = split /,/; $descr =~ s/\\x\{(\w{4})\}/chr(hex($1))/eg; # convert hex +values to chars $codes_hash{$code}{$language} = $descr; } } }
my ( $code, $descr ) = split /,/; $codes_hash{$code}{$language} = eval $descr;
|
|---|