Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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.


Comment on Re: reverse function
Select or Download Code

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 about the Monastery: (14)
As of 2014-07-22 16:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (119 votes), past polls