D
DJ Stunks
Hello all,
In order to not have to perpetually be escaping a vertical bar field
separator in my regular expressions I tried to use a variable instead
(as in _PBP_).
However, I'm getting some strange behavior. Specifically, perl
believes the match has succeeded, but the capture is not performed.
Here's a short but complete script which demonstrates the issue.
Please let me know if you have any ideas.
-jp
PS: witnessed on perl v5.8.7 Binary build 813 [148120] for
MSWin32-x86-multi-thread
C:\tmp>cat tmp2.pl
#!/usr/bin/perl
use strict;
use warnings;
my $BAR = q{|};
my $string = q{|this.string_contains-some-2342:stuff|};
if (my ($stuff) = $string =~ m{^\| ([^|]+) \|$}x) {
print "'$stuff' matched\n";
}
if (my ($stuff) = $string =~ m{^$BAR ([^|]+) $BAR$}xo) {
print "'$stuff' matched using half \$BARs\n";
}
if (my ($stuff) = $string =~ m{^$BAR ([^$BAR]+) $BAR$}xo) {
print "'$stuff' matched using all \$BARs\n";
}
__END__
C:\tmp>tmp2.pl
'this.string_contains-some-2342:stuff' matched
Use of uninitialized value in concatenation (.) or string at
C:\tmp\tmp2.pl line 14.
'' matched using half $BARs
Use of uninitialized value in concatenation (.) or string at
C:\tmp\tmp2.pl line 18.
'' matched using all $BARs
In order to not have to perpetually be escaping a vertical bar field
separator in my regular expressions I tried to use a variable instead
(as in _PBP_).
However, I'm getting some strange behavior. Specifically, perl
believes the match has succeeded, but the capture is not performed.
Here's a short but complete script which demonstrates the issue.
Please let me know if you have any ideas.
-jp
PS: witnessed on perl v5.8.7 Binary build 813 [148120] for
MSWin32-x86-multi-thread
C:\tmp>cat tmp2.pl
#!/usr/bin/perl
use strict;
use warnings;
my $BAR = q{|};
my $string = q{|this.string_contains-some-2342:stuff|};
if (my ($stuff) = $string =~ m{^\| ([^|]+) \|$}x) {
print "'$stuff' matched\n";
}
if (my ($stuff) = $string =~ m{^$BAR ([^|]+) $BAR$}xo) {
print "'$stuff' matched using half \$BARs\n";
}
if (my ($stuff) = $string =~ m{^$BAR ([^$BAR]+) $BAR$}xo) {
print "'$stuff' matched using all \$BARs\n";
}
__END__
C:\tmp>tmp2.pl
'this.string_contains-some-2342:stuff' matched
Use of uninitialized value in concatenation (.) or string at
C:\tmp\tmp2.pl line 14.
'' matched using half $BARs
Use of uninitialized value in concatenation (.) or string at
C:\tmp\tmp2.pl line 18.
'' matched using all $BARs