diff options
author | Bram <perl-rt@wizbit.be> | 2008-05-16 07:44:07 -0700 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2008-05-17 10:01:08 +0000 |
commit | 9649ed94a18776bcf75c3267a2d02b0759ed80be (patch) | |
tree | 0859cf03d1a2f5c1252f5d093ea3b53255a7058b | |
parent | 670096dbbfb0136e2e18faea6d91a574d6c24f17 (diff) | |
download | perl-9649ed94a18776bcf75c3267a2d02b0759ed80be.tar.gz |
[perl #39187] [DOC-PATCH]: perldoc -f reverse: examples (was: RE: Perlfunc needs to be made more clear regarding reverse in scalar context.)
From: "Bram via RT" <perlbug-followup@perl.org>
Message-ID: <rt-3.6.HEAD-9880-1210974244-1717.39187-15-0@perl.org>
p4raw-id: //depot/perl@33840
-rw-r--r-- | pod/perlfunc.pod | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 99acb78572..764deb07a5 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -4718,13 +4718,16 @@ of LIST in the opposite order. In scalar context, concatenates the elements of LIST and returns a string value with all characters in the opposite order. - print reverse <>; # line tac, last line first + print join(", ", reverse "world", "Hello"); # Hello, world - undef $/; # for efficiency of <> - print scalar reverse <>; # character tac, last line tsrif + print scalar reverse "dlrow ,", "olleH"; # Hello, world Used without arguments in scalar context, reverse() reverses C<$_>. + $_ = "dlrow ,olleH"; + print reverse; # No output, list context + print scalar reverse; # Hello, world + This operator is also handy for inverting a hash, although there are some caveats. If a value is duplicated in the original hash, only one of those can be represented as a key in the inverted hash. Also, this has to |