CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Perl 5.10 not backwards compatible with 5.8: Edit Log



char_boy
Novice

Nov 21, 2010, 5:39 AM


Views: 3793
Perl 5.10 not backwards compatible with 5.8

The following script runs on 5.8 but does not run on 5.10.


Code
use strict; 
my %SAM;
$SAM{chr2LHet} = 1;
$SAM{chr2RHet} = 1;
$SAM{chr3LHet} = 1;
$SAM{chr3RHet} = 1;
foreach my $chr (sort cmpChrs keys %SAM) {
print "CHR=$chr\n";
}
sub cmpChrs () {
if($a =~ /chr(\d+)/) {
my $numa = $1;
if($b =~ /chr(\d+)/) {
my $numb = $1;
if($numa < $numb) { return 1; }
else {
$a =~ s/chr\d+//;
$b =~ s/chr\d+//;
my %temp;
$temp{$a}=1;
$temp{$b}=1;
foreach my $key (sort cmpChrs keys %temp) {
if($key eq $a) { return 1; }
else { return -1; }
}
}
} else { return 1; }
}
return 1;
}

On 5.8 it does not crash and outputs the following:
CHR=LHet
CHR=RHet
CHR=LHet
CHR=RHet

On 5.10 it crashes with the following message:

Can't undef active subroutine at test.pl line 29.
Attempt to free unreferenced scalar: SV 0x1124fa0, Perl interpreter: 0x10f7010 at test.pl line 29.
Attempt to free unreferenced scalar: SV 0x1124fa0, Perl interpreter: 0x10f7010 at test.pl line 29.


I had to do the following to fix it:

Code
use strict; 
my %SAM;
$SAM{chr2LHet} = 1;
$SAM{chr2RHet} = 1;
$SAM{chr3LHet} = 1;
$SAM{chr3RHet} = 1;
foreach my $chr (sort {cmpChrs($a,$b)} keys %SAM) {
print "CHR=$chr\n";
}
sub cmpChrs () {
if($a =~ /chr(\d+)/) {
my $numa = $1;
if($b =~ /chr(\d+)/) {
my $numb = $1;
if($numa < $numb) { return 1; }
else {
$a =~ s/chr\d+//;
$b =~ s/chr\d+//;
my %temp;
$temp{$a}=1;
$temp{$b}=1;
foreach my $key (sort {cmpChrs($a,$b)} keys %temp) {
if($key eq $a) { return 1; }
else { return -1; }
}
}
} else { return 1; }
}
return 1;
}


I always thought that if a new version was not backwards compatible that they'd change the first number, so this should be Perl 6.x not 5.10.


(This post was edited by char_boy on Nov 21, 2010, 5:46 AM)


Edit Log:
Post edited by char_boy (Novice) on Nov 21, 2010, 5:45 AM
Post edited by char_boy (Novice) on Nov 21, 2010, 5:46 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives