Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^4: get solution as short as possible

by parv (Priest)
on Aug 17, 2011 at 18:20 UTC ( #920743=note: print w/replies, xml ) Need Help??


in reply to Re^3: get solution as short as possible
in thread get solution as short as possible

A(...) problem is that your last solution truncates hash if it has data. It's not appropriate for me. Though I'm not sure if moritz's version does this.

If you are objecting to destruction of %s, then mortiz's version does preserve the previous elements.

With a slight modification destructive construction changes to ...

%map = map { m/^ default_ (option_.+) $/x ? ( $1 => $def{ $_ } ) : () } keys %def ; @s{ keys %map } = values %map;

In any case ...

As there is no getting around search for interesting keys and generation of second key list, so just use ...

sub simple_fill { my ( $save , %def ) = @_; for ( keys %def ) { my ( $opt ) = ( $_ =~ m/^ default_ (option_.+) $/x ) or next; $save->{ $opt } = $def{ $_ }; } return; }

And then there is use of map|grep in void context for side effects, which some may not regard as "a nice looking, straightforward (...) version for everyday use".

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://920743]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2016-12-06 04:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (100 votes). Check out past polls.