Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"say" docs misleading #17100

Closed
p5pRT opened this issue Jul 20, 2019 · 8 comments
Closed

"say" docs misleading #17100

p5pRT opened this issue Jul 20, 2019 · 8 comments

Comments

@p5pRT
Copy link

p5pRT commented Jul 20, 2019

Migrated from rt.perl.org#134298 (status was 'pending release')

Searchable as RT134298$

@p5pRT
Copy link
Author

p5pRT commented Jul 20, 2019

From @haukex

Hi,

perlfunc says "`say LIST` is simply an abbreviation for `{ local $\ =
"\n"; print LIST }`". If that were true, the output of the following two
would be the same​:

$ perl -MData​::Dumper -E 'sub x{Dumper($\)}{local$\="\n";print(x())}'
$VAR1 = '
';

$ perl -MData​::Dumper -E 'sub x{Dumper($\)}say(x())'
$VAR1 = undef;

So I think the documentation is incorrect. I always thought `say LIST` was
simply an abbreviation for `print(LIST,"\n")` - at least that's how it
behaves (it's not `print LIST, $\`, as a simple test shows).

$ perl -E '$\="y"; print "x"; say "z"'
xyz

Thanks, Regards,
-- Hauke D

@p5pRT
Copy link
Author

p5pRT commented Jul 20, 2019

From @Grinnz

On Sat, 20 Jul 2019 00​:55​:51 -0700, haukex@​zero-g.net wrote​:

Hi,

perlfunc says "`say LIST` is simply an abbreviation for `{ local $\ =
"\n"; print LIST }`". If that were true, the output of the following two
would be the same​:

$ perl -MData​::Dumper -E 'sub x{Dumper($\)}{local$\="\n";print(x())}'
$VAR1 = '
';

$ perl -MData​::Dumper -E 'sub x{Dumper($\)}say(x())'
$VAR1 = undef;

So I think the documentation is incorrect. I always thought `say LIST` was
simply an abbreviation for `print(LIST,"\n")` - at least that's how it
behaves (it's not `print LIST, $\`, as a simple test shows).

$ perl -E '$\="y"; print "x"; say "z"'
xyz

It's definitely misleading, but I think the intent was to say that it's like setting `local $\ = "\n"` for just the call to print (not while evaluating its arguments). Your example actually shows that it is also not `print(LIST,"\n")`, because that would also append $\; it uses \n *instead* of $\. I will see if I can come up with a patch.

-Dan

@p5pRT
Copy link
Author

p5pRT commented Jul 20, 2019

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jul 20, 2019

From @Grinnz

On Sat, 20 Jul 2019 08​:26​:02 -0700, grinnz@​gmail.com wrote​:

On Sat, 20 Jul 2019 00​:55​:51 -0700, haukex@​zero-g.net wrote​:

Hi,

perlfunc says "`say LIST` is simply an abbreviation for `{ local $\ =
"\n"; print LIST }`". If that were true, the output of the following
two
would be the same​:

$ perl -MData​::Dumper -E 'sub x{Dumper($\)}{local$\="\n";print(x())}'
$VAR1 = '
';

$ perl -MData​::Dumper -E 'sub x{Dumper($\)}say(x())'
$VAR1 = undef;

So I think the documentation is incorrect. I always thought `say
LIST` was
simply an abbreviation for `print(LIST,"\n")` - at least that's how
it
behaves (it's not `print LIST, $\`, as a simple test shows).

$ perl -E '$\="y"; print "x"; say "z"'
xyz

It's definitely misleading, but I think the intent was to say that
it's like setting `local $\ = "\n"` for just the call to print (not
while evaluating its arguments). Your example actually shows that it
is also not `print(LIST,"\n")`, because that would also append $\; it
uses \n *instead* of $\. I will see if I can come up with a patch.

Patch is attached.

@p5pRT
Copy link
Author

p5pRT commented Jul 20, 2019

From @Grinnz

0001-update-say-docs-to-better-represent-reality.patch
From ef0c28a099eb447e341c2d841d18c1139d2a70be Mon Sep 17 00:00:00 2001
From: Dan Book <grinnz@grinnz.com>
Date: Sat, 20 Jul 2019 11:40:45 -0400
Subject: [PATCH] update say docs to better represent reality

---
 pod/perlfunc.pod | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod
index 0e50132907..066cd268db 100644
--- a/pod/perlfunc.pod
+++ b/pod/perlfunc.pod
@@ -6789,8 +6789,8 @@ X<say>
 =for Pod::Functions +say output a list to a filehandle, appending a newline
 
 Just like L<C<print>|/print FILEHANDLE LIST>, but implicitly appends a
-newline.  C<say LIST> is simply an abbreviation for
-C<{ local $\ = "\n"; print LIST }>.  To use FILEHANDLE without a LIST to
+newline at the end of the LIST instead of any value L<C<$\>|perlvar/$\>
+might have.  To use FILEHANDLE without a LIST to
 print the contents of L<C<$_>|perlvar/$_> to it, you must use a bareword
 filehandle like C<FH>, not an indirect one like C<$fh>.
 
-- 
2.20.1

@p5pRT
Copy link
Author

p5pRT commented Jul 20, 2019

From @haukex

Hi,

On Sat, 20 Jul 2019 08​:26​:02 -0700, grinnz@​gmail.com wrote​:

Your example actually shows that it is also not `print(LIST,"\n")`,
because that would also append $\; it uses \n *instead* of $\.

Oops, you're right of course! I do see more clearly what the current
wording is *trying* to say, although it is indeed still misleading.

On Sat, 20 Jul 2019, Dan Book via RT wrote​:

Patch is attached.

Looks good to me, thank you!

Best,
-- Hauke D

@p5pRT
Copy link
Author

p5pRT commented Jul 20, 2019

From @khwilliamson

Thanks, applied as c3d72fb
--
Karl Williamson

@p5pRT
Copy link
Author

p5pRT commented Jul 20, 2019

@khwilliamson - Status changed from 'open' to 'pending release'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant