in reply to Re^2: perldoc -lf anomaly
in thread perldoc -lf anomaly

These results clearly contradict the perldoc documentation:

That's not true. The docs don't say what happens if you use -l with -f func instead of a module.

Here's another anomaly

What do you think is anomalous? That it's looking up splice instead of $_? That's your error. You interpolated shell variable $_ into your shell command, and it apparently had the value splice.

And another one:

What do you think is anomalous? That output is correct too, and I have no idea what you think is wrong.

Replies are listed 'Best First'.
Re^4: perldoc -lf anomaly (%_)
by Anonymous Monk on May 08, 2026 at 09:41 UTC
    Ok I was confused about -lf (and -lv and -lq) and my $_ anomaly is pure facepalm. But what about this:
    % perldoc -v '%_'
    No documentation for perl variable '%_' found
    
    %_ is a special snowflake like $_ and @_ in that they can be used under strict without declaration and they all fail in the same way if you try to own them with my: Can't use global %_ in "my" (but our and local work on all of them). I like using it sometimes in one-liners and dirty scripts cause $_{$_} looks weird and cool and it works good and I like typing it! Anyway I made Claude Haiku 4.5 at duck.ai think about %_ for 36 seconds! I've never seen the robots get so confused. They insist it doesn't exist, or it's nothing special, or that it's a filehandle or a reference to the last call to stat lol:
    perl -Mstrict -Mwarnings -le '%_ = ( foo => 1, bar => 2 ); print "$_ = + $_{$_}" for keys %_'
    foo = 1
    bar = 2
    
    So why isn't it documented? I could swear I saw it somewhere once upon a time, or maybe not... What is it??? Thanks
      > 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

        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