Hello guys
Let there be a hash
%def = ( default_option_use_log => 1, default_option_read_conf => 1, default_option_run_debug => "false", default_output_path => "/tmp/vvv", default_name => "stat_", default_option_save_state => "true" );
We need to fill a new hash with keys based on filtered and changed keys of %def hash. Consider the following code:
foreach (map { /^default_option_(.*)/ ? $1 : () } keys %def) { $s{"option_$_"} = $def{"default_option_$_"}; } foreach (keys %s) { print "\%s: $_ => $s{$_}\n"; }
Is there a way to shorten the 'foreach' block or may be use different approach instead of 'foreach'. It would be great to eliminate double using 'default_option_' string, also '? : ()' condition looks not perfect. I need a nice-looking, laconic, as much Perl-ish as possible, solution.
Thanks
In reply to get solution as short as possible by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |