Re: __FILE__ works as bareword

[email protected] (Dan)
Newsgroups perl.perl5.porters
Message-ID <CABMkAVV+8bm+76=WKHO3_5Xa_2Ha4sn_LiO31eUNBdg1==W+2w@mail.gmail.com>
On Sat, Nov 29, 2025 at 1:14 AM Dan <[email protected]> wrote:

> On Sat, Nov 29, 2025 at 12:39 AM Jim Avera <[email protected]> wrote:
>
>> This may have come up before, I don't recall.   Special tokens like
>> __FILE__ are not interpolated if they appear in a position where a
>> bareword hash key is allowed.
>>
>>    perl -E 'my @a = (__FILE__ => 42); say $a[0];'     # v5.43.2
>>    >> __FILE__
>>
>> Is this a bug?
>>
>
> No; identifiers are also not resolved to subroutines or other keywords in
> scope by the autoquoting fat comma. The autoquoting unary minus, of course,
> has the opposite resolution (-__FILE__).
>

Also to add, this isn't specifically related to hashes (as noted your
example didn't even use one) but the two common ways to specify hash keys:
the fat comma, and hash key subscripts ($x{__FILE__}).

-Dan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.