--- "Lee, Janet" <[EMAIL PROTECTED]> wrote:
> Hi all.

Hi, Janet. =o)

> Everyone has been so helpful with my other questions, I thought I
> would put out another one.

Cool.

> I'm writing a script that searches through an array of hashes. One of
> the possible fields in the hash is "Comments" and sometimes the
> comments have characters such as ? or * in them. Right now, my search
> line looks like this
>   if ($myhash{$searchVar} =~ /$value/i) {
>       do stuff;
>   }
> which works fine for regular text, but chokes up if $value is
> something like ** due to the matching.  I know backslashes would help
> if I knew in advance it would be **, but the user sets the $value
> variable on the fly.  Is there an easy way to get around this
problem? 

try
  if ($myhash{$searchVar} =~ /\Q$value\E/i) {

which quotes metacharacters in the expression.
If that chokes on the $ in $value, then precede that line with 
  $value = '\Q' . $value . '\E';
but I don't think it will.

Paul

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

Reply via email to