Hi -
Here's something that gives your output (2nd example):
use strict;
use warnings;
my $input = '1,2,3,4,5,6,17-25,32-101:4,1,2,3,5';
my @ina = split /,/, $input;
my @outa;
my $i = 0;
for (@ina) {
if (/(\d+)-(\d+):(\d+)/) {
$outa[$i][0] = $1;
$outa[$i][1] = int (($2 + 1 - $1) / $3) * $3 + $1;
$outa[$i][2] = $3;
$i++;
next;
}
if (/(\d+)-(\d+)/) {
$outa[$i][0] = $1;
$outa[$i][1] = $2;
$outa[$i][2] = 1;
$i++;
next;
}
next unless /(\d+)/;
if ($i > 0 && $outa[$i - 1][1] == $1 - 1) {
$outa[$i - 1][1] = $1;
$outa[$i - 1][2] = 1;
next;
}
$outa[$i][0] = $1;
$outa[$i][1] = $1;
$outa[$i][2] = 1;
$i++;
}
for ($i = 0; $i <= $#outa; ++$i) {
print "$outa[$i][0] $outa[$i][1] $outa[$i][2]\n";
}
Please note that as is, this script would "close" ranges like:
17-22:2,23-30
into:
17 30 1
but that's for you to figure out.
It's also not very elegant :-).
Aloha => Beau.
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Friday, June 07, 2002 9:50 AM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Help with Ranges
Hello folks,
I am trying not to re-invent the wheels. So I was wondering whether
there is a little program that you good people might know of the would
do the following for me:
Here's an example:
input: 1,2,3,4,5,6,17-25,32-101:4
output:
1 6 1
17 25 1
32 100 4
output is "start end increment"
also, frames can be duplicated:
input: 1,2,3,4,5,6,17-25,32-101:4,1,2,3,5
output:
1 6 1
17 25 1
32 100 4
1 3 1
5 5 1
On top of that, I may, at times, want to have up to 10,000 command line
values. I know it sounds very strange, but it is for a movie studio with
very peculiar requirements.
Thanks in advance...
-r
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]