perhaps use qr// to "precompile" the search instead and use that new
precompiled var within your loop so you don't evaluate the if conditions
each looptime.

my $search;
   if ( $WholeMatchOnly )
   {
     if ( $IgnoreCase )
       { $search = qr/^\($pattern\)$/i }
     else
       { $search = qr/^\($pattern\)$/ }
   }
   else
   {
     if ( $IgnoreCase )
       { $search = qr/\($pattern\)/i }
     else
       { $search = qr/\($pattern\)/ }
   }

while( something ){
        $somthing =~ $search;
        ## and more!
        }

> -----Original Message-----
> From: David T-G [mailto:[EMAIL PROTECTED]]
> Sent: Friday, June 07, 2002 8:43 AM
> To: perl beginners
> Subject: changing behavior by user command
> 
> 
> Hi, all --
> 
> So I have this mp3 database script idea and I'm starting to 
> move into it
> (it feels good to think perlishly again, and I'm going to 
> want to be able
> to ignore case or not and search on substrings or not in my 
> code.  That's
> always been a problem for me: how can I modify my behavior based on
> conditions?
> 
> Clearly I could do something like (but probably not exactly 
> like; I have
> no idea whether or not this would parse but instead just want 
> to set the
> example)
> 
>   if ( $WholeMatchOnly )
>   {
>     if ( $IgnoreCase )
>       { /^\($pattern\)$/i }
>     else
>       { /^\($pattern\)$/ }
>   }
>   else
>   {
>     if ( $IgnoreCase )
>       { /\($pattern\)/i }
>     else
>       { /\($pattern\)/ }
>   }
> 
> but that, even sucked up like it is, is long, drawn-out, and 
> a stinker to
> maintain.  Is there a way to do something like
> 
>   if ( $WholeMatchOnly )
>     { $ABeg = '^' ; $AEnd = '\$' }
>   if ( $IgnoreCase )
>     { $MOpts =. 'i' }
> 
>   /$ABeg$pattern$AEnd/$MOpts
> 
> so that the match is configured dynamically based on the conditions
> going into it?
> 
> 
> TIA & HAND
> 
> :-D
> -- 
> David T-G                      * It's easier to fight for 
> one's principles
> (play) [EMAIL PROTECTED] * than to live up to them. -- 
> fortune cookie
> (work) [EMAIL PROTECTED]
> http://www.justpickone.org/davidtg/    Shpx gur 
> Pbzzhavpngvbaf Qrprapl Npg!
> 
> 

----------------------------------------------------------------------------
--------------------
The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to