in reply to bareword hash keys

You confusion is between '-' being part of the bareword, and - as the unary negation operator. perl -MO=Deparse,-p -e "$foo{-bar}" outputs $foo{-'bar'};. The scalar negation operator is defined rather oddly in perl -- when you try to negate a string, it doesn't nummify and then negate (which would give 0), but rather prepends a dash.

There is still some bareword magic going on, to turn the b (in your example) into 'b' rather then a call to the (non-existant) b() function.


Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

Replies are listed 'Best First'.
Re: Re: bareword hash keys
by John M. Dlugosz (Monsignor) on Jun 23, 2003 at 04:54 UTC
    Interesting. The "bareword is OK" context must propigate inward, too. I suppose that's a special case of the - and not something that applies to any operator that takes/returns a string. Quick check indicates that's the case.