Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Read a variable backwards..

by kcott (Abbot)
on Jan 06, 2014 at 12:41 UTC ( #1069506=note: print w/ replies, xml ) Need Help??


in reply to Read a variable backwards..

G'day sathya83aa,

I see a number of solutions involving breaking the string into individual characters and then recombining in reverse order. This isn't necessary as reverse in scalar context will do this for you.

When the context is already scalar, you can just use the reverse function:

$ perl -le 'my $x = "8940163...835"; my $y = reverse $x; print $y' 538...3610498

In list context, you can force scalar context with the scalar function:

$ perl -le 'my $x = "8940163...835"; print scalar reverse $x' 538...3610498

-- Ken


Comment on Re: Read a variable backwards..
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2014-07-14 02:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (254 votes), past polls