[Date Prev][Date Next][Thread Prev][Thread Next]
[Search]
[Date Index]
[Thread Index]
[FWP] Less fun with meta chars
Ok, I know I've made this more fun than it ought to be. I'm trying to escape
all meta characters in a string. I'm sure there is a module for this or a
cookbook solution, but that would be no fun. I'd like to maintain a little fun.
At the risk of being shamed by the simplicity of another solution, heres mine:
%meta = map {($_,1)} split('', '\|()[{^$*+?.');
$str = join('', map {if ($meta{$_}) {"\\$_"} else {$_}} split('', $str));
Ed Perry
==== Want to unsubscribe from Fun With Perl? Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
==== unsubscribe