Mailing List Archive

perlbug with either doc or "reverse" operator
@list = ("fred","barney","betty");
$a = reverse @list; # reverse in scalar context
print "$a\n"; # should print "derf" according to my reading of docs
# but instead prints "yttebyenrabderf"

so it looks like a join "" followed by reverse is happening. This doesn't
really match well with the docs. Does the same in perl4.036 as well.
It certainly surprised me. And I've been using Perl for a while. :-)

Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.teleport.com/~merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
Re: perlbug with either doc or "reverse" operator [ In reply to ]
Randal L. Schwartz wrote :
|| @list = ("fred","barney","betty");
|| $a = reverse @list; # reverse in scalar context
|| print "$a\n"; # should print "derf" according to my reading of docs
|| # but instead prints "yttebyenrabderf"
||
|| so it looks like a join "" followed by reverse is happening. This doesn't
|| really match well with the docs. Does the same in perl4.036 as well.
|| It certainly surprised me. And I've been using Perl for a while. :-)

I don't get the same in perl4.036, but I get 'ytteb' instead of 'derf'
so it looks like a football play (a double reverse with a handoff from
array to scalar in between :-)

Loading DB routines from $RCSfile: perldb.pl,v $$Revision: 4.0.1.3 $$Date: 92/06/08 13:43:57 $
Emacs support available.

Enter h for help.

main'(/tmp/perl-eOgUCZt:1): 0
DB<1> @list = ("fred","barney","betty");

DB<2> $a = reverse @list; # reverse in scalar context

DB<3> print "$a\n"; # should print "derf" according to my reading of docs
ytteb


--
Maybe we can fix reality one of these days. | John Macdonald
<- Larry Wall Carl Dichter -> | jmm@Elegant.COM
I'd be happy if we could just index it. |