in reply to Override "null filehandle"

The diamond operator reads from ARGV, not STDIN.
open my $INPUT, '<', \"my input\n"; *ARGV = $INPUT; print <>;

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Override "null filehandle"
by philipbailey (Curate) on Sep 04, 2023 at 08:49 UTC

    That's not quite true:

    % echo This is from STDIN|perl -e'print for <>' This is from STDIN % echo This is from ARGV > input1 % echo This is also from ARGV > input2 % perl -e'print for <>' input1 input2 This is from ARGV This is also from ARGV

    The <> operator looks first at at @ARGV and iterates line by line through each file specified as arguments to the script. But if there are no arguments (@ARGV is empty) then it falls back to reading from STDIN. This behaviour is documented in perlop, already linked to by the OP.

      The diamond operator reads from ARGV, not STDIN.
      That's not quite true

      choroba is correct though, in that <> is always equivalent to <ARGV>, as is described in the very documentation you referenced. The magical behavior you describe is not that of the <> operator in general, it is that of the ARGV filehandle, which modifies @ARGV in order for STDIN to be read automatically via the ARGV handle.

      Reworded for clarity, shortly after posting.

      <> always reads from ARGV. It's just that ARGV might in turn read from STDIN. Whether it does or not depends on @ARGV.