Assume that I have
and I want to constract a hash reference where BIRD is a key. Obviously I can not douse constant BIRD=>'footchicken';
because barewords on the lefthand side of => get quoted. Possible solutions are{ BIRD => 'Valery' }
both of which I don't like very much (for purely aesthetic reasons). It therefore occured to me that{ BIRD() => 'Valery' } { BIRD, 'Valery' }
does not only look nice (for me, that is), but should work. However, it does not. Printing it out with Data::Dumper, i.e.{ +BIRD => 'Valery' }
displays:use strict; use warnings; use Data::Dumper; use constant { BIRD => 'footchicken' }; print Dumper(+{ +BIRD => 'Valery' });
This puzzles me. Why do I see BIRD here? Monadic + binds stronger than => and this means that we have +BIRD on the left of =>. This is certainly not a bareword, so it should evaluate as an expression, yielding 'footchicken'. And even in the unlikely case Perl would regard it as bareword here, quoting the beast would be '+BIRD', not 'BIRD'.$VAR1 = { 'BIRD' => 'Valery' };
In reply to On quoting the lhs of '=>' by rovf
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |