in reply to Re: catch die from say
in thread catch die from say

"say $mail $textecourriel;"

From perlobj: Indirect Object Syntax (emboldened text from the documentation):

Outside of the file handle case, use of this syntax is discouraged as it can confuse the Perl interpreter. ...

Also, the "The 'indirect' feature" is disabled in v5.36 (see "perl5360delta: use v5.36").

I would recommend

$mail->say($textecourriel);

as a preferred syntax.

Update: See responses for why I have striken this recommendation.

— Ken

Replies are listed 'Best First'.
Re^3: catch die from say
by Corion (Patriarch) on Apr 01, 2024 at 07:23 UTC
    open( my $mail, "| mailx -r $from -s $sujet $courrielclient");

    ... in this case, $mail actually is the file handle case :)

Re^3: catch die from say
by ikegami (Patriarch) on Apr 01, 2024 at 13:41 UTC

    That's all wrong.

    say $mail $textecourriel; is NOT an instance of indirect method call syntax. It's not a method call at all. It's a named operator with a funky syntax.

    The indirect feature has no effect on this. (Neither does the indirect pragma.)

    It does NOT confuse the Perl interpreter (because say is always declared, and because the handle expression is limited to a simple scalar, a bareword (if you use the bareword_filehandles anti-feature), or a block).

    Unlike say $mail $textecourriel;, $mail->say( $textecourriel ); does invoke a method (of IO::Handle). This adds needless overhead and complexity. This is what should be avoided.

    The IO::Handle::say method doesn't use say. It instead emulates it using local $\ = "\n"; and print. This is not equivalent in an (admittedly obscure) corner case.

    The IO::Handle::say method ends up using print $mail $textecourriel; anyway. Because that's how one prints to a file handle in Perl. It's not something to avoid as you suggest.


    If it's in perlfunc, it's not a method call. As such, none of the following are instances of indirect method call syntax:

    • print FH LIST
    • print BLOCK LIST
    • printf FH LIST
    • printf BLOCK LIST
    • say FH LIST
    • say BLOCK LIST
    • map BLOCK LIST
    • grep BLOCK LIST
    • system BLOCK LIST
    • exec BLOCK LIST
Re^3: catch die from say
by Timka (Acolyte) on Apr 01, 2024 at 06:11 UTC

    "This leads us to our next strong suggestion: Use direct object syntax at all times."