Peng Yu <> writes:
> Only the first statement prints the reversed result correctly. I'm
> confused why the other three don't print as I expected. How to print
> the reversed result without using the intermediate variable $rstring?
>
> $ cat reverse.pl
> #!/usr/bin/perl
>
> use warnings;
>
> $string = "abc";
> $rstring=reverse($string);
> print "$rstring\n";
> print reverse($string), "\n";
> print(reverse($string), "\n");
> print((reverse($string)), "\n");
>
> $ ./reverse.pl
> cba
> abc
> abc
> abc
john@ecce:~$ perl -e 'print reverse("abc"), "\n"'
abc
john@ecce:~$ perl -e 'print scalar(reverse("abc")), "\n"'
cba
perl -e 'print reverse("abc") . "\n"'
cba
perldoc -f reverse
reverse LIST
In list context, returns a list value consisting of the
elements 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.
--
John Bokma
Read my blog:
http://johnbokma.com/
Hire me (Perl/Python):
http://castleamber.com/