sort a word "system" in perl/shell without using built in
functions

output should be emssty

Answer Posted / umesh

$value = "system";
@SortedArray = split('',$value);
$strlength = @SortedArray;
print "Current sort @SortedArray
";
$swapped = 0;
for($i=0; $i < $strlength; $i++){
for (my $j = 0; $j < $strlength-1-$i; $j++) {
if($SortedArray[$j] gt $SortedArray[$j+1]){
$tmp = $SortedArray[$j];
$SortedArray[$j] = $SortedArray[$j+1];
$SortedArray[$j+1] = $tmp;
$swapped =1;
}
}
if ($swapped) {
next;
}
}

print join('', split(' ', "@SortedArray")), "
";

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

In CPAN module, name an instance you use.

543


How does polymorphism work in perl?

518


You want to read command-line arguements with perl. How would you do that?

496


Why should I use the -w argument with my Perl programs?

561


Distinguish my and local?

520






What is the use of '>>' in perl?

541


What $! In perl?

527


What is the difference between perl list and perl array?

470


How do you give functions private variables that retain their values between calls?

565


Explain string comparison operators in perl.

555


What is the importance of perl warnings?

539


What does -> symbol indicates in Perl?

568


Explain split function in perl?

562


Why do we use "use strict" in perl?

533


How can you use Perl warnings and what is the importance to use them?

538