in reply to The weirdest problem with undef
This gave me errors like this:#!/usr/bin/perl use strict; foreach my $item ('top', 'heavy', 'fool') { my (@array1, @array2); a_function($item); print "@array1\n"; print "@array2\n"; } sub a_function { my $item = shift; push @array1, 'crap'; push @array2, 'dumb'; }
This clearly tells me that the subroutine is looking for global variables. Declaring them as my inside a loop doesn't create global variables. So moving them to the top, like this, works fine:Global symbol "@array1" requires explicit package name at ./test_loop. +pl line 18. Global symbol "@array2" requires explicit package name at ./test_loop. +pl line 19. Execution of ./test_loop.pl aborted due to compilation errors.
... my (@array1, @array2); foreach my $item ('top', 'heavy', 'fool') { ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: The weirdest problem with undef
by insaniac (Friar) on Dec 22, 2004 at 19:24 UTC | |
|
Re^2: The weirdest problem with undef
by Jasper (Chaplain) on Dec 23, 2004 at 09:54 UTC | |
|
Re^2: The weirdest problem with undef
by blazar (Canon) on Jun 28, 2005 at 10:18 UTC |