in reply to Re^4: perldoc -lf anomaly (%_)
in thread perldoc -lf anomaly

> So why isn't it documented?

Because contrary to $_ and @_ it has no function

> I could swear I saw it somewhere once upon a time, or maybe not...

People are exploiting the side effect that it's a global and doesn't need to be declared.

> What is it???

The typeglob / symbol _ is global to allow the scalar and array slots $_ and @_ to hold magic.

The hash slot is undefined but still global and can be (ab)used for syntactic sugar.

Like

# No my/our %_ lives in main:: %_ = (a => 1, b => 2); # global variable in package main

See also this SO discussion https://stackoverflow.com/questions/36723739/undocumented-perl-variable#36724370

Edit

perldoc -v and perlvar should probably be expanded to show a generic explanation for such "reserved" special variables

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^6: perldoc -lf anomaly (%_)
by LanX (Saint) on May 08, 2026 at 12:19 UTC
    Follow up:

    I just noticed that while @ENV is reserved special, @a is not. Compare %ENV and $a ...

    Has this always been the case?

    I kind of remember @a being "weird" too.

    $ perl -e'use strict;@1=(666)' $ perl -e'use strict;@STDOUT=(666)' $ perl -e'use strict;@ENV=(666)' #but $ perl -e'use strict;@a=(42)' Global symbol "@a" req +uires explicit package name (did you forget to declare "my @a"?) at - +e line 1. $ perl -e'print $]' 5.040003$

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

      I think that's because $a and $b are package variables, not globals. Same with @F under -a.

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
        Hmm yes, $a and $b live - if needed - in the current package and not main::

        $ perl -E'package tst; sort{$a le $b} 1..100; say exists $tst::{a}; us +e strict; say $a;' 1

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        see Wikisyntax for the Monastery