in reply to Problem in Number Range
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 | |
by cognizant (Pilgrim) on Oct 03, 2005 at 16:11 UTC |