Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

sort a word "system" in perl/shell without using built in
functions

output should be emssty

Answer Posted / vipul dalwala

======= PERL SCRIPT (sortword.pl) =========

#!/usr/bin/perl

my $word = $ARGV[0];
$sortword = "";
$lastchar = "";

while($word =~ /(.)/g)
{
$lastchar = $1;
if( $sortword ) {
$flag = "";
$newsortword = "";
while($sortword =~ /(.)/g) {
if( $lastchar gt $1 || $flag
eq "charcovered") {

$newsortword =
$newsortword.$1;
$flag = "greater" if($flag
ne "charcovered")
}
else {
$newsortword =
$newsortword.$lastchar.$1;
$flag = "charcovered";
}
}
if( $flag ne "charcovered" ) {
$newsortword =
$newsortword.$lastchar;
}

$sortword = $newsortword;
}
else {
$sortword = $lastchar;
}
}

print $sortword."\n";


======= PERL SCRIPT =========

Run the script as:

sortword.pl "system"

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What $! In perl?

921


What are different data types that perl supports. Elaborate on them.

1006


Define print() function in perl?

879


What are the arguements we normally use for perl interpreter?

919


How to find the length of an array in perl?

983


What does `$result = f() .. g()' really return?

1116


What is the difference between use and require in perl programming?

896


What are prefix dereferencer?

871


what are steps to do to lock the sony ericsson mobile with password?

2167


Demonstrate subroutines in perl with a simple example.

829


Explain the various characteristics of perl.

914


What is the difference between perl array and perl hash?

1004


Differentiate between arrays and list in perl.

953


Explain perl. What are the advantages of programming in perl?

983


How many types of primary data structures in Perl and what do they mean?

1350