On Sat, Jan 17, 2004 at 10:19:24PM -0800, Kim Helliwell wrote:
> I need to take a string like this:
>
> UA-UI1,3,4,6
>
> and expand it into an array of components like this:
>
> UA1 UA3 UA4 UA6 UB1 UB3 UB4 UB6 ... UI1 UI3 UI4 UI6
How's this?
my $str = "UA-UI1,3,4,6";
if ( my( $from, $to, $nums ) = ( $str =~ /^(\w+)-(\w+)(\d(?:,\d)*)?$/ ) ) {
my @nums = split /,/, $nums;
for ( my $chars = $from; $chars le $to; $chars ++ ) {
foreach ( @nums ) {
print "$chars$_\n";
}
}
}
else {
die "Couldn't parse $str!\n";
}
--
Andy <[EMAIL PROTECTED]> - http://anime.mikomi.org/ - Community Anime Reviews
It's easy to fall into the habit of choosing rigor over vigor. [...] We
already have lots of computer languages with rigor, but not so many with
vigor. -- Larry Wall in <[EMAIL PROTECTED]>