$temp =~ m/(\[0-9\])blah$1/;
I think you meant
$temp =~ m/(\[0-9\])blah\1/;
in which case any special characters in the content of the backreference
\1 would not be treated special. IOW, "[0-9]blah[0-9]" would
match, but not "[0-9]blah6":
#!/usr/bin/perl
use strict;
use warnings;
for my $temp ("[0-9]blah[0-9]", "[0-9]blah6") {
printf "%-15s ", $temp;
if ($temp =~ /(\[0-9\])blah\1/) {
print "matched\n";
} else {
print "didn't match\n";
}
}
prints
[0-9]blah[0-9] matched
[0-9]blah6 didn't match
while, if you replace \1 with $1 in the above regex, it prints
Use of uninitialized value in concatenation (.) or string at ./671663.
+pl line 8.
[0-9]blah[0-9] matched
[0-9]blah6 matched
This is because $1 isn't defined here, thus the regex effectively
becomes /(\[0-9\])blah/...
Update: added demo code.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|