Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: reverse function

by moritz (Cardinal)
on Jun 29, 2012 at 11:57 UTC ( #979108=note: print w/replies, xml ) Need Help??


in reply to reverse function

As the documentation for reverse explains, using it in scalar context does string reversal, not list reversal.

Thus it joins all arguments into a string and reverses it.

If you want the other output, either leave off the scalar, or write

print join '', reverse(1, 'ab'));

Note that this behavior confuses many newcomers (though usually they wonder why print reverse "abc"; doesn't reverse anything) and is inconsistent with how things are generally done elsewhere in Perl 5, so in Perl 6 reverse always reverses lists, and flip always reverses strings.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://979108]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2016-10-01 01:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (574 votes). Check out past polls.