I have the below script from a user. When ran on perl 5.8.4 and 5.12.4, it prints 1, but not in 5.10.0 (prints 0).
perl -e ' my $a=0; my $net="<*2>ColBnk<2"; if (($net =~ s/([(<])/$1/g) != ($net =~ s/([>)])/$1/g)){$a++} print $a;'
Is this the problem with the code (comparing string variable with != instead of ne or could this be due to missing semicolon after $a++).
I tried to debug it by printing the value of ($net =~ s/([(<])/$1/g) and ($net =~ s/([>)])/$1/g) and both are printing the same value. Please refer the below code
use strict;
use warnings;
#/mu/bin/perl -e '
my $a=0;
my $net="<*2>ColBnk<2";
my $test="<*2>ColBnk<2";
$test =~ s/([(<])/$1/g;
print "\n$test" ;
$test =~ s/([>)])/$1/g;
print "\n$test" ;
if (($net =~ s/([(<])/$1/g) ne ($net =~ s/([>)])/$1/g)){$a++;}
print "\n Value of a =$a";
#'
Could you please provide any pointers.
Thanks for your help,
Ashish
I can confirm that it works in 5.8.9 and 5.14.2, but does not work in 5.10.0. It must be a bug introduced somewhere between 5.8 and 5.10, and subsequently fixed. I used Porting/bisect.pl to find out where it broke. It was this commit, which was introduced in Perl 5.9.4. It was then fixed by this commit, which was introduced in Perl 5.10.1.
When I tried using bisect.pl, I kept getting an error about needing to have a C compiler (even though I do have one installed). It turns out that bisect.pl doesn’t use the normal compiler detection of Perl’s Configure script (presumably to save time). If the default doesn’t work, you need to use the
-Doption of bisect.pl to set it. (e.g., I used-D{cc,ld}=/usr/bin/gcc).You can find the exact change that introduced the bug by performing the following steps:
If you must use Perl 5.10.0, then you can work around the bug by storing the result of each
s///ginto a temporary variable, and then comparing the two variables:But a better solution is to upgrade to a fixed version. Perl 5.10 is officially end-of-life, but you could install 5.10.1 anyway if you don’t want to make a large change. Or you can upgrade to 5.12 or 5.14.