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

 



sangfroid
Novice

Sep 4, 2010, 12:53 PM

Post #1 of 6 (1342 views)
string reverse Can't Post

Hi,

I just wrote a simple perl script, which will reverse the string.

Code
 #/bin/perl 
$string1="I am here";
$rev = reverse($string1);
print (reverse($string1));
print $rev;


Why doesn't the first print statement print the string in reverse ?? Is it not supposed to print in reverse ??


shawnhcorey
Enthusiast


Sep 4, 2010, 6:24 PM

Post #2 of 6 (1333 views)
Re: [sangfroid] string reverse [In reply to] Can't Post

Try:

Code
my $string1="I am here";  
my $rev = reverse($string1);
print (scalar reverse($string1));
print $rev;


See `perldoc -f scalar`

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


tej.87g
Novice

Sep 4, 2010, 10:22 PM

Post #3 of 6 (1326 views)
Re: [shawnhcorey] string reverse [In reply to] Can't Post

Hey evan i tried it but its not working
following is my code:


Code
my $str="Perl"; 

my $str1=reverse ($str);

print "This is str : =>: $str\n This is str1:=>$str1";
print "scalar reverse($str)";

In first print it is printing properly, but in next one it is printing :

Code
scalar reverse($str)

Am i doing any mistake?


Zhris
Enthusiast

Sep 4, 2010, 10:49 PM

Post #4 of 6 (1322 views)
Re: [tej.87g] string reverse [In reply to] Can't Post


Code
print "scalar reverse($str)"; 
print (scalar reverse($str));


Chris


sangfroid
Novice

Sep 5, 2010, 1:09 PM

Post #5 of 6 (1298 views)
Re: [shawnhcorey] string reverse [In reply to] Can't Post

I didn;t get exactly about this "scalar" thing. can you explain a bit more ? I am new to perl.

By the way, so far as I know, variable is of scalar type... but from where scalar is coming here into context ??Shocked


shawnhcorey
Enthusiast


Sep 5, 2010, 1:22 PM

Post #6 of 6 (1295 views)
Re: [sangfroid] string reverse [In reply to] Can't Post


In Reply To
I didn;t get exactly about this "scalar" thing. can you explain a bit more ? I am new to perl.

By the way, so far as I know, variable is of scalar type... but from where scalar is coming here into context ??Shocked


Open a Command Prompt and in it, type:

perldoc -f scalar

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".

 
 


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

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