The following script runs on 5.8 but does not run on 5.10. I distilled out a short program with the heart of the bug. The output of this script could be achieved easily without recursion but my real sort routine does need to be recursive, but I removed most of the code. Ignore the fact that this doesn't achieve something useful as is, the point is it runs on 5.8 and not on 5.10.
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: 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; } ------------------------------------------------------------------------------------------------------------------------------------------- The strangest thing is that it has no problem with the first two top level calls of the subroutine where it does call itself recursively, and it has no problem with the third top level call where it does not call itself recursively. It crashes on the fourth top level call where it also does not call itself recursively and is basically the same as the previous time it was called. So that's very strange and inconsistent behavior leading me to believe it is not intended. But I'm really not an expert. Not sure if this is a bug in 5.10 or if I was using an illegal syntax that just wasn't enforced in 5.8. But in any case it's curious. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/