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

Hi Monks, I have a basic question to ask. I have so many global variables in my file. When i dont use use strict; use warnings; everything goes well. When i use them i get compilation errors like this-- <quote> Global symbol "@records" requires explicit package name at per_user_qna_detail.p l line 80. </quote> How to get rid of these errors. Thanks NT

Replies are listed 'Best First'.
Re: basic perl question
by toolic (Bishop) on Jun 23, 2009 at 13:22 UTC
Re: basic perl question
by stevemayes (Scribe) on Jun 23, 2009 at 13:10 UTC

    You have to declare your variables with strict and warnings.

    e.g.  my @records or possibly  our @records

    This might have been better asked in the chatterbox

Re: basic perl question
by CountZero (Bishop) on Jun 23, 2009 at 13:53 UTC
    From the docs of the strict module:
    This generates a compile-time error if you access a variable that wasn't declared via our or use vars, localized via my(), or wasn't fully qualified. Because this is to avoid variable suicide problems and subtle dynamic scoping issues, a merely local() variable isn't good enough. See my in the perlfunc manpage and local in the perlfunc manpage.
    use strict 'vars'; $X::foo = 1; # ok, fully qualified my $foo = 10; # ok, my() var local $foo = 9; # blows up package Cinna; our $bar; # Declares $bar in current package $bar = 'HgS'; # ok, global declared via pragma
    The local() generated a compile-time error because you just touched a global name without fully qualifying it. Because of their special use by sort(), the variables $a and $b are exempted from this check.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: basic perl question
by Unforgiven (Hermit) on Jun 23, 2009 at 13:55 UTC
    Without seeing the code itself it's hard to say, but the first thing I'd check is that everything's declared with "my" (or "our", or whatever is appropriate). Failing that, check that your variables don't go out of scope before you use them.