I forgot to add what I have done so far. I did:

#!/usr/bin/perl

use strict;
use warnings;

my @array = (5,3,2,1,4);
my $n = @array;

for my $i (0 .. $n-1) {
  for my $j (0 .. $n-1) {
      if ($array[$j+1] < $array[$j]) {  #compare the two neighbors
        $tmp = $array[$j];              # swap $array[j] and $array[j+1]
          @array[$j, $j+1] = @array[$j+1, $j];
      }
  }
}

for my $elem (@array) {
  print "$elem";

Yet this wont work. I get:

Global symbol "$tmp" requires explicit package name at ./obj8-2.pl line 12.
Execution of ./obj8-2.pl aborted due to compilation errors.


Any ideas?

Reply via email to