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
What $! In perl?
What are different data types that perl supports. Elaborate on them.
Define print() function in perl?
What are the arguements we normally use for perl interpreter?
How to find the length of an array in perl?
What does `$result = f() .. g()' really return?
What is the difference between use and require in perl programming?
What are prefix dereferencer?
what are steps to do to lock the sony ericsson mobile with password?
Demonstrate subroutines in perl with a simple example.
Explain the various characteristics of perl.
What is the difference between perl array and perl hash?
Differentiate between arrays and list in perl.
Explain perl. What are the advantages of programming in perl?
How many types of primary data structures in Perl and what do they mean?