|There's more than one way to do things|
Re: What does the dash before hash assignment means?by kcott (Canon)
|on Sep 03, 2013 at 21:02 UTC||Need Help??|
"I saw some perl code with a dash before key name for hash assignment. Any special meaning? Does that equal to a quotation mark? Thanks for any help. fun(-url => $httpRefer);"
Firstly, let's look at how Perl parses that (with and without the dash):
So, clearly something special is happening. Is it the dash or the fat comma?
No fat comma and we're still getting "-url" parsed as "(-'url')". This indicates that the dash is the cause; the perlop: Symbolic Unary Operators documentation bears this out:
"If the operand is an identifier, a string consisting of a minus sign concatenated with the identifier is returned."
Without actually looking at the parsing process, you could have run some simple tests:
Commenting out the lines with barewords:
While I can see that "(-url => $httpRefer)" might be used as a key/value pair in some hash assignment, you don't actually show any code performing such an operation. [If you thought you did, you may need to ask another question :-)] Regardless, the code I've posted here involves no hashes at all: the unary minus operator, in this context, is unrelated to hashes!