Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.96k stars 555 forks source link

[doc] perldoc -f print: confusing wording regarding misinterpretation of variable as an operator #18661

Open x-qq opened 3 years ago

x-qq commented 3 years ago

Where https://perldoc.perl.org/perlfunc#print-FILEHANDLE-LIST

Description The following wording is confusing:

(NOTE: If FILEHANDLE is a variable and the next token is a term, it may be misinterpreted as an operator
unless you interpose a + or put parentheses around the arguments.)

In my opinion it would be better to recommend universal use of method-like syntax for print in this document: $fh->print($stuff) because it helps to reduce ambiguity.

leonerd commented 3 years ago

+1.

At the very least, various bits of documentation around syntax sometimes use words like "term", which don't have a clear definition elsewhere in docs - or in the implementation for that matter ;) We could do a good cleaning up of these.

But also I think it would be good to encourage the far-less-ambiguous method style of $fh->print(), and leave the indirect notation forms almost as a historic footnote; explaining what users might come across in old code but not encouraging them to actually use those in newly-written stuff.

rsFalse commented 3 years ago

I will add, that Damian Conway in the book "Perl Best Practices" recommends to use braces:

Putting braces around the filehandle helps it stand out clearly: print {$file} $name, $rank, $serial_num, "\n";

( Once I got the suggestion to use braces after asking a similar question (with similar example) in forum: https://perlmonks.org/?node_id=1231158 - "Ambiguous '~~' in 'print scalar ~~list'" )