[sf-perl] Unmatched [ in regex; marked by <-- HERE in m/[ <-- HERE NO/

Al Sary asary at liveops.com
Mon Jan 15 16:27:23 PST 2007


Sorry if I'm missing some context, but the problem seems pretty clear:

$ perl -e '$f=qq/[/; s/$f//'   
Unmatched [ in regex; marked by <-- HERE in m/[ <-- HERE / at -e line 1.


A \Q should fix it:

$ perl -e '$f=qq/[/; s/\Q$f//'

In other words:

>      $field =~ s/$field//g;         <============ THIS IS WHERE THE
>PROBLEM OCCURS.
>  
>
      $field =~ s/\Q$field//g;


(disclaimer: I didn't try to  understand what you are trying to do)


Quinn Weaver wrote:

>On Mon, Jan 15, 2007 at 04:31:11PM -0700, Loo, Peter # PHX wrote:
>  
>
>>Hello,
>> 
>>I am getting the following error when I hit the following record when
>>trying to m// the field "[NO".
>>    
>>
>
>  
>
>>[...]
>>    
>>
>
>Hi, Peter,
>
>I can't replicate your problem using the code you posted.  For me, it
>works with or without the "|| $field =~ m/\W+/)" part.  (Without
>it, the regex doesn't match, but it doesn't die with a compilation
>error.)
>
>I suspect you may have a syntax error.  Check your code carefully.
>It may be that you've accidentally chopped off the / that ends the
>regex, or something.  The code should look like this:
>
>Variant 1:
>
>  
>
>>elsif ($field =~ m/^[0-9]*\s+[0-9]$/ || $field =~ m/\W+/) {
>>    
>>
>
>Variant 2:
>
>  
>
>>elsif ($field =~ m/^[0-9]*\s+[0-9]$/) {
>>    
>>
>
>If that doesn't help, please post more of the surrounding code, and
>we'll have another crack at it.
>
>Thanks,
>
>--
>qw (Quinn Weaver); #President, San Francisco Perl Mongers
>=for information, visit http://sf.pm.org/weblog =cut
>_______________________________________________
>SanFrancisco-pm mailing list
>SanFrancisco-pm at pm.org
>http://mail.pm.org/mailman/listinfo/sanfrancisco-pm
>  
>


More information about the SanFrancisco-pm mailing list