in reply to need help to split list
And the output is:use strict; use Data::Dumper; my $list = "1-5,6a-e,7,9-12,89xDC-G"; my @s = map { my @t = split /-/; my $l = length($t[0]) - 1; # length less 1 $#t == 0 ? $_ : $t[0] + 0 eq $t[0] ? # pure number? $t[0] .. $t[1] : map { substr($t[0],0,$l) . $_ } substr($t[0],$l,1) .. $t[1] } split /,/, $list; print Dumper(\@s);
Update: Typo fixed - 89xDC-G (was 89xFC-G). Thanks OverlordQ!$VAR1 = [ 1, 2, 3, 4, 5, '6a', '6b', '6c', '6d', '6e', '7', 9, 10, 11, 12, '89xDC', '89xDD', '89xDE', '89xDF', '89xDG' ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: need help to split list
by OverlordQ (Hermit) on Oct 26, 2003 at 07:40 UTC | |
by Roger (Parson) on Oct 26, 2003 at 11:06 UTC |