#! /usr/bin/perl -w use strict; my @list = qw /3 5 6 2 12/; bubble_sort(\@list,scalar @list); print "@list\n"; sub bubble_sort { my $arrays_ref = shift || ""; my $num = shift || ""; for (my $i = 0; $i < $num - 1; $i++) { for (my $j = 0; $j < $num - $i - 1; $j++) { if ($arrays_ref->[$j] > $arrays_ref->[$j-1]) { my $tmp = $arrays_ref->[$j]; $arrays_ref->[$j] = $arrays_ref->[$j-1]; $arrays_ref->[$j-1] = $tmp; } print "@$arrays_ref\n"; } } return $arrays_ref; }