[EMAIL PROTECTED] wrote:

> 
> Morning,
> 
> I am working on some code which will check for a line starting with any
> Perl Metacharacters, and precede it with a '/'.
> Here is what i have thus far:
> 
>                         if ($LogLinePrefix =~
> /[\^\$\+\*\?\.\|\(\)\{\}\\\[\]]/)
>                                 {
>                                         $LoglinePrefix =~
> s/[\^\$\+\*\?\.\|\(\)\{\}\\\[\]]*/\\{$1}/g ;
>                                 }
> 
> Unfortunately, this isn't working.  Can anyone make a suggestion?

Your code doesn't look for a line starting with a metachar, but any
metachar in the line.  If that's what you intended:

        if (/[\^\$+*?.|(){}\\\[\]]/) {
                s/([\^\$+*?.|(){}\\\[\]])/\\$1/g;
        }

You can add your $vrbl in there if not using $_.

You could just try the substitute rather than testing first (not sure
what the timing diff would be) :

        s/([\^\$+*?.|(){}\\\[\]])/\\$1/g;

If indeed you wanted just the first char as you said:

        s/^([\^\$+*?.|(){}\\\[\]])/\\$1/;

you can add the first ^ anchor to the RE and drop the /g.

-- 
  ,-/-  __      _  _         $Bill Luebkert    Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to