There's more than one way to do things | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Context: a StackOverflow question on how to use constants as hash keys.
Note that the module itself mentions the following: For example, you can't say $hash{CONSTANT} because CONSTANT will be interpreted as a string. Use $hash{CONSTANT()} or $hash{+CONSTANT} to prevent the bareword quoting mechanism from kicking in. Similarly, since the => operator quotes a bareword immediately to its left, you have to say CONSTANT() => 'value' (or simply use a comma in place of the big arrow) instead of CONSTANT => 'value'. The OP used &CONSTANT => 'value' which works but doesn't inline the constant (i.e. expand it during compile time). ikegami pointed me to a different way which I found more pleasing than CONSTANT() which, as he rightly noted, leaks the internal implementation of constants.
I wanted to verify it behaves exactly the same, so I tried running it through B::Deparse, B::Terse, and B::Concise.
says the code is identical. Terse needs some tweaking to skip the pointers:
But Concise shows a slight difference:
From the documentation it seems the P just means that A was parenthesized. I can imagine this information could be valuable to Perl (e.g. in the LHS of an assignment, but the structures of scalar versus list assignments are much more different); but probably not in this case. Update: Topics for meditation include other possible syntaxes (e.g. A ,=> 12), personal preferences, explanation of the Concise's output, etc.
In reply to Using constants as hash keys by choroba
|
|