On Tuesday 03 July 2007 10:43, Amichai Teumim 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?

The problem is that you're defining $tmp but not scoping it.  Then you don't 
use it, so you don't need it anyway.

(Hint, re-think about the array index ranges you're looking at)
-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000     

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


Reply via email to