in reply to Why does "flush filehandle" work?

You hit upon an (older) corner of perl's OOP syntax, the "indirect object" notation. Since flush is a method what your first code really translates to would be $gp->flush (which would be the proper replacement if you want to be explicit). In recent perls you can als disable it with no feature q{indirect}. See https://www.effectiveperlprogramming.com/2020/06/turn-off-indirect-object-notation/ for a bit more detailed explanation.

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

Replies are listed 'Best First'.
Re^2: Why does "flush filehandle" work?
by ikegami (Patriarch) on Jan 29, 2025 at 14:28 UTC

    It's even disabled by default in the feature bundle for 5.36+

    $ perl -e'flush STDOUT;' $ perl -e'no feature qw( indirect ); flush STDOUT;' Bareword found where operator expected (Do you need to predeclare "flu +sh"?) at -e line 1, near "flush STDOUT" syntax error at -e line 1, near "flush STDOUT" Execution of -e aborted due to compilation errors. $ perl -e'use v5.36; flush STDOUT;' Bareword found where operator expected (Do you need to predeclare "flu +sh"?) at -e line 1, near "flush STDOUT" syntax error at -e line 1, near "flush STDOUT" Execution of -e aborted due to compilation errors.

    (Mentioned in the article.)