Samy_rio has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks, I have some problem in number ranges.
I have tried the following coding, its working fine for three digit ranges (123-135) but it may vary in number of digits(12-14, 1234-1256).
use strict; my $a="123-135, 111-119, 127-130, 140-145"; print "Original : $a\n"; my @a = split (/\, /, $a); eval{s/^(\d{2})(\d+)\-(\d{2})(\d+)$/&digit($1,$2,$3,$4)/egsi;} for (@a +); print "Changed : "; print "$_\t" for @a; sub digit{ my ($f, $f1, $s, $s1)=@_; if ($f == $s){ $s=$s1; } else{ $s=~s/\d//; $s.=$s1; } return qq($f$f1-$s); }
But when i get the input like this, the above coding not works, is there any other way to do?
my $a="9-35, 11-19, 1272-1340, 1430-1435";Is there any module?
Regards,
Velusamy R.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem in Number Range
by jasonk (Parson) on Oct 03, 2005 at 15:10 UTC | |
|
Re: Problem in Number Range
by ikegami (Patriarch) on Oct 03, 2005 at 15:28 UTC | |
|
Re: Problem in Number Range
by InfiniteSilence (Curate) on Oct 03, 2005 at 16:03 UTC | |
|
Re: Problem in Number Range
by cognizant (Pilgrim) on Oct 03, 2005 at 15:30 UTC | |
by Samy_rio (Vicar) on Oct 03, 2005 at 15:53 UTC | |
by cognizant (Pilgrim) on Oct 03, 2005 at 16:11 UTC |