in reply to Problem in Number Range

The problem is in the algorithm. Assuming that a<b:

#!/usr/bin/perl -w use strict; my $str = $ARGV[0]||"123-135, 111-119, 127-130, 140-145"; #borrowed from ikegami print "Original string \n" . $str; print "\nEnding string \n"; print show($_) for map { [ split(/-/, $_) ] } split(/\s*,\s*/, $str); sub show { my (@anums) = split //,$$_[0]; my (@bnums) = split //,$$_[1]; my ($output) = $$_[0] . '-'; my $switch = 0; if ($#anums != $#bnums){ return $$_[0]; } for(0..$#bnums){ if(defined($anums[$_])){ #if same, do nothing #if larger, include if (($bnums[$_] > $anums[$_])|| ($switch)){ $output .= $bnums[$_]; $switch++; } } } return $output . ' '; }

Celebrate Intellectual Diversity