in reply to Problem in Number Range

Try this
use strict; my $a="123-135, 1-119, 1270-1280, 1420-1452"; print "Original : $a\n"; my @a = split (/\, /, $a); eval{s/^([0-9]*)([0-9]+)\-([0-9]*)([0-9]+)$/&digit($1,$2,$3,$4)/egsi;} + for (@a); print "Changed : "; print "$_\t" for @a; sub digit{ my ($f, $f1, $s, $s1)=@_; my ($fs, $se); if($s =~ /([0-9]+)([0-9])/) { $fs = $1; $se = $2; } if ($f == $s) { $s=$s1; } elsif($f=~/^$fs/) { $s=$se.$s1; } else{ $s=~s/\d//; $s.=$s1; } return qq($f$f1-$s); }

Replies are listed 'Best First'.
Re^2: Problem in Number Range
by Samy_rio (Vicar) on Oct 03, 2005 at 15:53 UTC

    Here, i am getting output as

    Changed  : 123-35       1-19     1270-80 1420-52

    instead of

    Changed  : 123-35       1-119     1270-80 1420-52

    That is, "1-119" is a correct range, but its changed as "1-19". This case happening in all correct ranges like "1-10" also.

    Regards,
    Velusamy R.

      Modify the last snipped of the code as follows:
      else{ #$s=~s/\d//; $s.=$s1; }