in reply to get solution as short as possible
A map with a ternary that returns () in one case is usually a good place for a grep:
for (grep /^default_option_/, keys %def) { my (undef, $option) = split /_/, $_, 2; $s{$option} = $def{$_}; }
(untested).
Update: Another approach without an explicit loop, but with map/grep:
my @keys = grep /^default_option_/, keys %def; my @short_keys = map +(split /_/, $_, 2)[1], @keys; @s{@short_keys} = @def{@keys};
Regarding your wish to shorten the code, I can recommend The path to mastery.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: get solution as short as possible
by throop (Chaplain) on Aug 17, 2011 at 15:23 UTC | |
|
Re^2: get solution as short as possible
by Anonymous Monk on Aug 17, 2011 at 11:34 UTC | |
by dexahex (Novice) on Aug 17, 2011 at 13:20 UTC | |
by parv (Parson) on Aug 17, 2011 at 18:20 UTC |