Bubble Sort

#!/usr/local/bin/perl
#program that sorts an array (Bubble Sort)

# read the array from standard input one item at a time
print ("Enter the array to sort, one item at a time.\n");
print ("Enter an empty line to quit.\n");
$count = 1;
$inputline = <STDIN>;
chop ($inputline);
while ($inputline ne "") {
        @array[$count-1] = $inputline;
        $count += 1;
        $inputline = <STDIN>;
        chop ($inputline);
}

# now sort the array
$count = 1;
while ($count < @array) {
        $pos = 1;
        while ($pos < @array) {
                if ($array[$pos - 1] gt $array[$pos]) {
                        @array[$pos-1,$pos] = @array[$pos,$pos-1];
                }
                $pos++;
        }
        $count++;
}

# finally, print the sorted array
print ("@array\n");