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
How and what are closures implemented in perl?
How to merge two arrays in perl?
Explain substr function in perl?
You want to read command-line arguements with perl. How would you do that?
Explain the difference between "my" and "local" variable scope declarations. ?
Explain perl.
Explain splicing of arrays?
How to connect to SQL server through Perl?
“Perl regular expressions match the longest string possible”. What is the name of this match?
What is perl scripting?
How to remove a directory in perl?
What are the advantages and disadvantages of perl language?
In Perl, there are some arguments that are used frequently. What are that arguments and what do they mean?
Why to use perl scripting?
What are the various perl data types based on the context?