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

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?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (13)
As of 2015-11-30 17:36 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (778 votes), past polls