Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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".


Comment on Re^4: get solution as short as possible
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://920743]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (11)
As of 2014-09-01 08:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (299 votes), past polls