sub bubbleSort { my @list = @_; my $cutoff; my $last_changed = @list; while ( $last_changed ) { $cutoff = $last_changed; $last_changed = 0; for my $current ( 1 .. $cutoff ) { my $previous = $current - 1; if ( $list[$current] < $list[$previous] ) { ($list[$current], $list[$previous]) = ($list[$previous], $list[$current]); $last_changed = $previous; } } } return @list; }