[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Fw: Perl question
- To: http://www.outformations.com/~dek
- Subject: Re: Fw: Perl question
- From: <http://dummy.us.eu.org/robert>
- Date: Fri, 9 Sep 2005 19:23:30 -0700 (PDT)
I think the problem is the semi-colon (';'). Because it is itself a word
separator, Perl regular expressions may not be able to deal with it properly.
Using \W rather than \b might work. For example,
if ($phrase =~ /\b$word1\W/) ...
--- http://www.outformations.com/~dek wrote:
> How are you doing? Had a client ask me this one today, do you have a few
> minutes to take a look?
>
> Cheers,
> Dale Kiefling
> Outformations, Inc.
> 415 699-0421
> - ----- Forwarded by Dale Kiefling/Outformations/US on 09/09/2005 12:54 PM
> - -----
>
> "John Goebel - Forrests Music" <http://www.forrestsmusic.com/~jgoebel>
> 09/08/2005 09:31 PM
>
> To
> <http://www.outformations.com/~dek>
> cc
>
> Subject
> Perl question
>
> Hi Dale;
>
> Thanks for the advice today, I'll run some more tests and let you know the
> results. You asked me to email you the perl question, which is whether you
> can re-define \b. This little test program will illustrate the problem;
> test 1 matches, test 2 fails.
> Start Code
> #!/usr/bin/perl
> $word = 'lorée';
> $word1 = 'loreé';
> @phrase =
> ('is','lorée','or','loreé','in','this','phrase','?');
> $phrase = join (' ',@phrase);
> #test1
> if ($phrase =~ /\b$word\b/){
> print "\\b$word\\b found in '@phrase' \n";
> }else{
> print "\\b$word\\b not found in '@phrase' \n";
> }
> #test2
> if ($phrase =~ /\b$word1\b/){
> print "\\b$word1\\b found in '@phrase' \n";
> }else{
> print "\\b$word1\\b not found in '@phrase' \n";
> }
> End Code
>
> I worked around it by encoding and decoding with:
> #
> -
>
--------------------------------------------------------------------------------
> - ---
>
> sub EncodeEntity{
> my($w) = @_;
> #use /g, use /s (function may be used on Long Description which may have
> embedded
> #line endings, do NOT use /i (reduces chances of false positive).
> $w =~ s/\&(.*?)\;/ZAMPZ$1ZSMCLNZ/gs;
> return $w;
> }
> #
> -
>
--------------------------------------------------------------------------------
> - ---
> sub DecodeEntity{
> my($w) = @_;
> $w =~ s/ZAMPZ(.*?)ZSMCLNZ/\&$1\;/gs;
> return $w;
> }
> #
> -
>
--------------------------------------------------------------------------------
>
> More than a little crude, but it works.
>
> Regards,
> JohnNo virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.344 / Virus Database: 267.10.19/93 - Release Date: 9/8/2005