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 to add elements in a hash in perl?

853


What does next statement do in perl?

928


How do you you check the return code of a command in perl?

937


What are scalar data and scalar variables?

1054


What does last statement do in perl?

942


Why to use perl scripting?

929


How to connect to SQL server through Perl?

979


How will you access an element of a perl array?

887


Explain the arguments for perl interpreter.

1138


Explain splicing of arrays?

862


In CPAN module, name an instance you use.

906


What is the use of -t?

906


How to access parameters passed to a subroutine in perl?

900


Mention how many ways you can express string in Perl?

964


Explain the execution of a program in perl.

921