Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2018-05-20 22:17 GMT
Find Nodes?
    Voting Booth?