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
Comment on the scope of variables in perl.
What can be done for efficient parameter passing in perl?
Which of these is a difference between Perl and C++ ?
What are perl strings?
What is perl dbi?
What are the different ways to run cgi?
What is Perl?
How to start perl in interactive mode?
What are the different types of perl operators?
How will you access an element of a perl array?
How to create a package?
How to read a single line from a file in perl?
Explain what is lvalue?
How many types of primary data structures in Perl and what do they mean?
How to do comment in perl?