http://www.perlmonks.org?node_id=958759


in reply to Re^2: map problem
in thread map problem

I like a modification of your middle suggestion best:

my %y = map { "prefix_".$_ => 1 } qw(a b c);
There's no need to put $_ inside quotes, only to have Perl do variable interpolation on that string. :)

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Replies are listed 'Best First'.
Re^4: map problem
by Marshall (Canon) on Mar 09, 2012 at 18:17 UTC
    That will work just fine and dandy as near as I can tell.
    GREAT! - understandable! (in terms of what it does).
    For something like this I would probably add a comment in the code for others as tip to why this "understandable thing" was needed. Not just for the future readers, but you may even forget "why" after a few years. That stuff has happened to me before! If the technique is so tricky that you had to think a lot about it, put in a comment.

    But, yes,  "prefix_".$_ => 1 is "easy on the eyes" (and the brain)