in reply to hash with multiple values per key
It's not entirely clear what format your initial data structure is taking. Are the values a single string? Are an array of values?
Assuming that they are array refs, and that your ranges are ordered from lesser value to greater value, this should work just fine:
If your ranges could be reversed, then the following adaptation would work:my %hash = ( a => ['15-19',30,35,120], b => ['15-17','30-35',40], c => ['15-18',30,35,120], ); for (values %hash) { @$_ = map {/^(\d+)-(\d+)$/ ? ($1..$2) : $_} @$_; } use Data::Dumper; print Dumper(\%hash);
- Millerfor (values %hash) { @$_ = map {!/^(\d+)-(\d+)$/ ? $_ : ($1 < $2) ? ($1..$2) : reverse +($2..$1)} @$_; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: hash with multiple values per key
by eric256 (Parson) on Aug 10, 2007 at 23:26 UTC |