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

Re: [FWP] More fun with meta chars



On Fri, Aug 27, 1999 at 02:33:30PM -0500, Edward M. Perry wrote:
> 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.
> 

Hmm, you still need the \Q and \E.

$b = 'x]**[y';

Ronald

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