in reply to weird subroutine behavior

I cannot even begin to fully fathom what your attempting but it appears your algorithm has some type of odd dependency on the order of the keys. If I change,

foreach my $str (sort {($substrings{$b}[1]-$substrings{$b}[0]) <=> ($s +ubstrings{$a}[1]-$substrings{$a}[0]) || $substrings{$a}[0] < => $substrings{$b}[0]} keys %substrings){
to
foreach my $str (sort {($substrings{$b}[1]-$substrings{$b}[0]) <=> ($s +ubstrings{$a}[1]-$substrings{$a}[0]) || $substrings{$a}[0] < => $substrings{$b}[0]} sort keys %substrings){
Then the runs are identical.

-derby

Update: Yikes! scratch all of that except, I cannot even begin to fully fathom. There is something wrong with the sort (as pointed out by kyle).

Replies are listed 'Best First'.
Re^2: weird subroutine behavior
by flaviusm (Acolyte) on Apr 02, 2008 at 16:34 UTC

    I added the extra "sort" in front of "keys" but there was not change in behavior: the subroutine didn't work as expected.

    I don't know if there is something related with my perl version (v5.8.7 built for cygwin-thread-multi-64int) but I will try it on a different computer, too.