On 7/3/07, Amichai Teumim <[EMAIL PROTECTED]> wrote:
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?


Yes, you are not defining $tmp with my.  Also, you are not using $tmp,
so you should just get rid of it.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to