CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
String reverse function doesn't work!!!

 



joycetipping
New User

Dec 1, 2009, 8:36 PM

Post #1 of 4 (305 views)
String reverse function doesn't work!!! Can't Post

For some reason, my reverse function doesn't seem to work properly. It won't reverse a string or a number, but it will work if we split it into a list and then join it back together. For example, here's what perlconsole gives me:

Perl> reverse (12345);
12345

Perl> reverse ("string");
string

Perl> join '', reverse (split //, "string");
gnirts

I'm running perl v.5.10.0 on Ubuntu. Any help is much appreciated -- I'm kinda weirded out. :)

Joyce


7stud
Enthusiast

Dec 1, 2009, 8:53 PM

Post #2 of 4 (302 views)
Re: [joyce.tipping] String reverse function doesn't work!!! [In reply to] Can't Post

What do you get when you type "perldoc -f reverse"?


mr-b
Novice

Dec 1, 2009, 9:19 PM

Post #3 of 4 (297 views)
Re: [joyce.tipping] String reverse function doesn't work!!! [In reply to] Can't Post

reverse (12345);
reverse "12345";

both wont work, in docs it says:

print scalar reverse 12345;
54321 is result.

gotta force scalar on the reverse


joycetipping
New User

Dec 1, 2009, 9:29 PM

Post #4 of 4 (295 views)
Re: [joyce.tipping] String reverse function doesn't work!!! [In reply to] Can't Post

Aha! Indeed, using scalar reverse works:

Perl> scalar reverse (12345);
54321

Truth be told, I had come across the documentation somewhere online but couldn't make much sense out of it. Takes practice I guess. :)

Thanks a bunch!!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives