in reply to Why does "flush filehandle" work?

A tool to use to figure out what is going on is Deparse. It shows you how perl interprets the code you give it. It comes with your perl. Here is an example of using it that demonstrates your question.

First, a full script that contains the syntax referenced:

$ cat flush.pl use warnings; use strict; open(my $fh, '> /dev/null'); flush $fh;

Now, tell perl to parse the code and show you its interpretation of it instead of running it:

$ perl -MO=Deparse flush.pl use warnings; use strict; open my $fh, '> /dev/null'; $fh->flush; flush.pl syntax OK

Note how it changed the flush $fh; to $fh->flush;

This demonstrates the "indirect object notation" that others are providing information about.

Replies are listed 'Best First'.
Re^2: Why does "flush filehandle" work?
by LanX (Saint) on Feb 04, 2025 at 17:00 UTC
    Light warning:

    Deparse is mostly correct, like in this case.

    I'd say in well over 99% of the cases.

    But it's using heuristics for back- engineering the source from the op tree and I've seen cases where it was wrong.

    One of the reasons is that optimizing the OP tree implies information loss. *

    But there is also a list of perl idiosyncracies which make that harder to accomplish.

    So please take the results with a grain of salt.

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

    *) for instance the indirect notation here