Saving a transliteration table in perl

Posted by user246100 on Stack Overflow See other posts from Stack Overflow or by user246100
Published on 2011-03-10T15:53:22Z Indexed on 2011/03/10 16:10 UTC
Read the original article Hit count: 252

Filed under:
|

I want to transliterate digits from 1 - 8 with 0 but not knowing the number at compile time. Since transliterations do not interpolate variables I'm doing this:

@trs = (sub{die},sub{${$_[0]} =~ tr/[0,1]/[1,0]/},sub{${$_[0]} =~ tr/[0,2]/[2,0]/},sub{${$_[0]} =~ tr/[0,3]/[3,0]/},sub{${$_[0]} =~ tr/[0,4]/[4,0]/},sub{${$_[0]} =~ tr/[0,5]/[5,0]/},sub{${$_[0]} =~ tr/[0,6]/[6,0]/},sub{${$_[0]} =~ tr/[0,7]/[7,0]/},sub{${$_[0]} =~ tr/[0,8]/[8,0]/});

and then index it like:

$trs[$character_to_transliterate](\$var_to_change);

I would appreciate if anyone can point me to a best looking solution.

© Stack Overflow or respective owner

Related posts about perl

Related posts about transliterate