Saturday, May 31, 2014

Reverse print a string the hard way

Script

#!/usr/bin/perl

print ("Enter a string: ");
my $i;
my $string = <STDIN>;
@string=split//,$string;

print ("The reverse of this string is:\n");
for ($i = $#string; $i >= 0; $i--)
{
print $string[$i];
}
print ("\n\n");


Execution

Enter a string: The Internet is a network of networks.
The reverse of this string is:

.skrowten fo krowten a si tenretnI ehT



Enter a string: RATS LIVE ON NO EVIL STAR
The reverse of this string is:

RATS LIVE ON NO EVIL STAR



Enter a string: University of California, Berkeley is one of the top Engineering institutions in the United States.
The reverse of this string is:

.setatS detinU eht ni snoitutitsni gnireenignE pot eht fo eno si yelekreB ,ainrofilaC fo ytisrevinU


1 comment:

  1. If you’re looking for Python development in Poland, you may be interested to know more about the developers from this eastern european country. Check out this article to learn more about Java software development company in Ukraine.

    ReplyDelete