in reply to Re: file handle var for print command
in thread file handle var for print command

This also works as expected, but I couldn't find a documented explanation for it:
$self->{fh}->print("test with print\n");

Replies are listed 'Best First'.
Re^3: file handle var for print command
by Fletch (Bishop) on Sep 24, 2025 at 14:36 UTC

    Filehandle GLOBs behave like IO::Handle instances (but aren't actually for purposes of inheritance according to the BUGS entry in the IO::Handle docs) so that's just a normal method call to the print method and doesn't get into weird indirect object parsing corners.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      Not quite.

      They behave like IO::File objects (since 5.12).

      $ perl -e'STDOUT->foo' Can't locate object method "foo" via package "IO::File" at -e line 1.

      They do obey inheritance.

      $ perl -e'use IO::File; IO::File::say( *STDOUT, "ok" )' Undefined subroutine &IO::File::say called at -e line 1. $ perl -e'use IO::File; IO::Handle::say( *STDOUT, "ok" )' ok $ perl -e'STDOUT->say( "ok" )' ok

      (IO::Handle's docs is merely saying IO::File isn't a derivable class since My::IO::File->new will create an IO::File "object" instead of a My::IO::File object.)

      And the issue raised wasn't why it works; it was about where it's documented. I could not find it either.