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

Re: Hash filter one-liner not working as expected

by nysus (Vicar)
on Mar 17, 2019 at 10:38 UTC ( #1231353=note: print w/replies, xml ) Need Help??


in reply to Hash filter one-liner not working as expected

Doh! I didn't have the proper syntax. Forgot I was dealing with a hash reference in the map function. This works:

my %colors = map { $_ => $hash->{$_} } grep { $_ =~ /color$/ } keys %$ +hash;

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re^2: Hash filter one-liner not working as expected
by vr (Deacon) on Mar 17, 2019 at 11:56 UTC

    You had syntax for something else. If number of hash elements was odd, Perl would have warned you sooner than you loose 25 minutes, it was simply bad fortune. Btw, it could be:

    my %colors = %$hash{ grep /color$/, keys %$hash };

    with use 5.020; to warn would-be users.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2019-06-27 10:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (111 votes). Check out past polls.

    Notices?