[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[FWP] More fun with meta chars



Ok, I'm really not that dull. Really. I was writing a funtion that takes
two strings and replaces all occurances of characters in $a that occur in
string $b. I over-generalized the problem to include all meta characters 
(I only want a subset). Having defined a built-in function, I am now deluged 
with RTFM. 

   %meta = map {($_,1)} split('', $b);
   $a = join('', map {if ($meta{$_}) {"\\$_"} else {$_}} split('', $a));

Ok, I was being stupid. Really. I forgot that a character set removes the
meta-ness from its characters. What I wanted was simply this:

   $a =~ s{[$b]}{_}g;

Let the mockery begin.

Ed Perry

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe