http://www.perlmonks.org?node_id=939373


in reply to Quicksort problem

@end = quicksort(3, 2, 6, 5, 4); foreach (@end) { print "$_ "; } print "\n"; sub quicksort { @arr=@_; if($#arr < 1) { return @arr; } my $pivot=pop(@arr); my @less; my @great; foreach (@arr) { # print "@_"; if ($_<$pivot) { push @less, $_; } else { push @great, $_; } } return quicksort(@less), $pivot, quicksort(@great); }
$#arr returns the index of the last element of @arr.
so if @arr contains 1 element then its index will be 0 i.e < 1