Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hi nysus,

I'm surprised you don't get an error, as I am getting this with your code:

syntax error at line 31, near "$hash{"

Anyway, changing your code line with the grep and map as follows:

my %colors = map { $_ => $hash->{$_} } grep { $_ =~ /color$/ } keys %$ +hash;
or like this:
my %colors = map { $_ => $$hash{$_} } grep { $_ =~ /color$/ } keys %$h +ash;
works for me. Your error seems to be in this: %$hash{$_} (in the map).

Output of Data::Dumper on the %colors hash:

$ perl $VAR1 = { 'test_menu_hl_color' => '#a74d3d', 'test_widget_color' => '#eee3b7', 'test_text_color' => '#000000', 'test_widget_header_color' => '#c6b989', 'test_menu_color' => '#004d59', 'background_color' => 'ffffff', 'test_article_background_color' => '#ceddd2', 'test_widget_title_color' => '#ffffff', 'test_menu_text_color' => '#ffffff', 'test_link_color' => '#31e500', 'test_headline_color' => '#7b0706', 'header_textcolor' => 'blank' };

In reply to Re: Hash filter one-liner not working as expected by Laurent_R
in thread Hash filter one-liner not working as expected by nysus

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (1)
As of 2023-09-23 11:00 GMT
Find Nodes?
    Voting Booth?

    No recent polls found