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

Perlfunc needs to be made more clear regarding reverse in scalar context. #8459

Closed
p5pRT opened this issue May 23, 2006 · 10 comments
Closed

Comments

@p5pRT
Copy link

p5pRT commented May 23, 2006

Migrated from rt.perl.org#39187 (status was 'resolved')

Searchable as RT39187$

@p5pRT
Copy link
Author

p5pRT commented May 23, 2006

From theodore@websitters.com

Perlfunc gives these as examples of reverse​:

print reverse <>; # line tac, last line
first
undef $/; # for efficiency of <>
print scalar reverse <>; # character tac, last line
tsrif

This is very clear for using reverse in list context,
but not so clear for reversing the characters in the
list, and very unclear regarding reversing a string.
I've read this many times, but didn't realize that you
could reverse a string until someone told me today. Is
there any way you can add a line to make this more
clear? Perhaps something like​:

print scalar reverse $_;

Thank you for your attention to this matter.
-Ted


  Homeschool World
  http​://www.home-school.com

  Our homeschool groups area​:
  http​://www.home-school.com/groups/

  Try our homeschool forum!
  http​://www.home-school.com/forums/


@p5pRT
Copy link
Author

p5pRT commented May 23, 2006

From james@mastros.biz

On Tue, May 23, 2006 at 02​:34​:11AM -0700, Theodore Pride wrote​:

# New Ticket Created by Theodore Pride
# Please include the string​: [perl #39187]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=39187 >

Perlfunc gives these as examples of reverse​:

print reverse <>; # line tac, last line
first
undef $/; # for efficiency of <>
print scalar reverse <>; # character tac, last line
tsrif
I think bringing <> into the picture at all can be confusing, because it's
also context-sensitive. We could say

print scalar reverse "\n!dlrow ,olleH"; # Traditional greeting
print join(", ", reverse 1..9), "\n"; # Count down

... which mostly avoids unclear context. Remember, the audience for the
examples is people who didn't get it from the text; we should minimize the
number of subtle things going on, ideally to only the subtle things we're
trying to show in the example.

  -=- James Mastros
  Preacher to chiors

@p5pRT
Copy link
Author

p5pRT commented May 23, 2006

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

@p5pRT
Copy link
Author

p5pRT commented May 24, 2006

From theodore@websitters.com

My point is that the current description doesn't
really make it clear that you can reverse a string,
not just a list, by using scalar context. I've been
using join '', reverse split //, $_ for the last year
on Perlmonks, and only a day ago did someone tell me
that you could do the same thing with scalar reverse
$_ . An example should be added that explicitly shows
scalar reverse $_

-Ted

--- James Mastros via RT <perlbug-followup@​perl.org>
wrote​:

On Tue, May 23, 2006 at 02​:34​:11AM -0700, Theodore
Pride wrote​:

# New Ticket Created by Theodore Pride
# Please include the string​: [perl #39187]
# in the subject line of all future correspondence
about this issue.
# <URL​:
https://rt-archive.perl.org/perl5/Ticket/Display.html?id=39187

Perlfunc gives these as examples of reverse​:

print reverse <>; # line tac, last line
first
undef $/; # for efficiency of <>
print scalar reverse <>; # character tac, last
line
tsrif
I think bringing <> into the picture at all can be
confusing, because it's
also context-sensitive. We could say

print scalar reverse "\n!dlrow ,olleH"; #
Traditional greeting
print join(", ", reverse 1..9), "\n"; # Count
down

... which mostly avoids unclear context. Remember,
the audience for the
examples is people who didn't get it from the text;
we should minimize the
number of subtle things going on, ideally to only
the subtle things we're
trying to show in the example.

   \-=\- James Mastros
   Preacher to chiors

  Homeschool World
  http​://www.home-school.com

  Our homeschool groups area​:
  http​://www.home-school.com/groups/

  Try our homeschool forum!
  http​://www.home-school.com/forums/


@p5pRT
Copy link
Author

p5pRT commented May 24, 2006

From @tamias

On Tue, May 23, 2006 at 05​:30​:47PM -0700, Theodore Pride wrote​:

My point is that the current description doesn't
really make it clear that you can reverse a string,
not just a list, by using scalar context. I've been
using join '', reverse split //, $_ for the last year
on Perlmonks, and only a day ago did someone tell me
that you could do the same thing with scalar reverse
$_ . An example should be added that explicitly shows
scalar reverse $_

I understand that the current examples were unclear to you, and it's
certainly worth patching to make the behavior clearer. But would you mind
if I asked what you thought was happening in this case​:

undef $/;
print scalar reverse <>;

?

Ronald

@p5pRT
Copy link
Author

p5pRT commented May 24, 2006

From chromatic@wgz.org

On Tuesday 23 May 2006 17​:30, Theodore Pride wrote​:

My point is that the current description doesn't
really make it clear that you can reverse a string,
not just a list, by using scalar context. I've been
using join '', reverse split //, $_ for the last year
on Perlmonks, and only a day ago did someone tell me
that you could do the same thing with scalar reverse
$_ . An example should be added that explicitly shows
scalar reverse $_

Why bring print and $_ into it?

  my $backwards = 'sdrawkcab';
  my $forwards = reverse $backwards;

-- c

@p5pRT
Copy link
Author

p5pRT commented May 16, 2008

From p5p@spam.wizbit.be

On Tue May 23 02​:34​:11 2006, theodore@​websitters.com wrote​:

Perlfunc gives these as examples of reverse​:

print reverse <>; # line tac, last line
first
undef $/; # for efficiency of <>
print scalar reverse <>; # character tac, last line
tsrif

This is very clear for using reverse in list context,
but not so clear for reversing the characters in the
list, and very unclear regarding reversing a string.
I've read this many times, but didn't realize that you
could reverse a string until someone told me today. Is
there any way you can add a line to make this more
clear? Perhaps something like​:

print scalar reverse $_;

Thank you for your attention to this matter.
-Ted

Patch that changes the examples in perlfunc/reverse attached.

@p5pRT
Copy link
Author

p5pRT commented May 16, 2008

@p5pRT
Copy link
Author

p5pRT commented May 16, 2008

p5p@spam.wizbit.be - Status changed from 'open' to 'resolved'

@p5pRT p5pRT closed this as completed May 16, 2008
@p5pRT
Copy link
Author

p5pRT commented May 17, 2008

From @demerphq

2008/5/16 Bram via RT <perlbug-followup@​perl.org>​:

On Tue May 23 02​:34​:11 2006, theodore@​websitters.com wrote​:

Perlfunc gives these as examples of reverse​:

print reverse <>; # line tac, last line
first
undef $/; # for efficiency of <>
print scalar reverse <>; # character tac, last line
tsrif

This is very clear for using reverse in list context,
but not so clear for reversing the characters in the
list, and very unclear regarding reversing a string.
I've read this many times, but didn't realize that you
could reverse a string until someone told me today. Is
there any way you can add a line to make this more
clear? Perhaps something like​:

print scalar reverse $_;

Thank you for your attention to this matter.
-Ted

Patch that changes the examples in perlfunc/reverse attached.

Thanks. Applied as 33840.

http​://public.activestate.com/cgi-bin/perlbrowse/p/33840

Cheers,
yves

--
perl -Mre=debug -e "/just|another|perl|hacker/"

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

No branches or pull requests

1 participant