in reply to Quicksort problem
$#arr returns the index of the last element of @arr.@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); }
so if @arr contains 1 element then its index will be 0 i.e < 1
In Section
Seekers of Perl Wisdom