Chris McEwen wrote:

 

> 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?

 

I presume you mean that you want every metacharacter to be preceded by a slash, and it’s a backward slash, as in your code? If so you want to put brackets () round the part between the first pair of slashes (otherwise you haven’t defined what $1 is), remove the * as the ‘g’ is doing the work, and also remove the curly brackets between the second pair of slashes (what was their purpose?), eg

 

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

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to