in reply to Expand Ranges in Lists of Numbers
By the way, in your example, this line:use Data::Dumper; print Dumper [evalexp('21, 35, 42-45, 19')]; sub evalexp { my $str = shift; $str =~ s/\s//g; $str =~ s/-/../g; return eval $str; }
pushes "strings" onto the array. You probably should "cast" $piece with int:push @expanded, $piece;
instead. (The ranges don't suffer from this side effect [caused by split i believe] because of the .. operator.) Data::Dumper reveals such details.push @expanded, int $piece;
Happy coding. :)
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (jeffa) Re: Expand Ranges in Lists of Numbers
by The Mad Hatter (Priest) on Jun 08, 2003 at 20:22 UTC |