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 to add elements in a hash in perl?
What does next statement do in perl?
How do you you check the return code of a command in perl?
What are scalar data and scalar variables?
What does last statement do in perl?
Why to use perl scripting?
How to connect to SQL server through Perl?
How will you access an element of a perl array?
Explain the arguments for perl interpreter.
Explain splicing of arrays?
In CPAN module, name an instance you use.
What is the use of -t?
How to access parameters passed to a subroutine in perl?
Mention how many ways you can express string in Perl?
Explain the execution of a program in perl.