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

How and what are closures implemented in perl?

878


How to merge two arrays in perl?

1040


Explain substr function in perl?

1025


You want to read command-line arguements with perl. How would you do that?

888


Explain the difference between "my" and "local" variable scope declarations. ?

1054


Explain perl.

938


Explain splicing of arrays?

910


How to connect to SQL server through Perl?

1047


“Perl regular expressions match the longest string possible”. What is the name of this match?

935


What is perl scripting?

930


How to remove a directory in perl?

983


What are the advantages and disadvantages of perl language?

914


In Perl, there are some arguments that are used frequently. What are that arguments and what do they mean?

901


Why to use perl scripting?

994


What are the various perl data types based on the context?

929