jerrygarciuh has asked for the wisdom of the Perl Monks concerning the following question:

Oh learned ones, why does my declaration of @words in line six cause the error "Global symbol @words requires explicit package name" ?
TIA
JG
#!/usr/bin/perl -w use strict; use warnings; use diagnostics; @words = qw(baloney has a first name); open (TEXTFILE,">>/menu.txt") || die "where's the damn file? : $!"; print TEXTFILE @words; close (TEXTFILE) || die ("close damn you : $!";

Replies are listed 'Best First'.
Re: Error: requires explicit package name
by runrig (Abbot) on Sep 12, 2001 at 23:23 UTC
Re: Error: requires explicit package name
by acid06 (Friar) on Sep 12, 2001 at 23:17 UTC
    One of the consequences of the strict pragma is that you have either to predeclare your variables (which in your case would be done using my @words = qw(baloney has a first name)) or to use explicit package names, like @main::words = qw(baloney has a first name) (which is not recommended, except in some cases)...

    acid06
    perl -e "print pack('h*', 16369646), scalar reverse $="
Re: Error: requires explicit package name
by rchiav (Deacon) on Sep 12, 2001 at 23:12 UTC
    You need to declare it as
    my @words = qw(baloney has a first name);
    Read up on my and strict

    Rich

Re: Error: requires explicit package name
by RayRay459 (Pilgrim) on Sep 12, 2001 at 23:49 UTC
    When using "use Strict;" you will need to use "my" infront of @words. You can find more info by doing a search on Strict. I don't have a link because i have not yet figured out how to link without posting the whole url. :)
    enjoy and happing hunting.
    Ray