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

When I use the following variable assignments...

use strict; # set some path variables. $msagdir = '/stlouis4/msag'; $tempdir = $msagdir . '/tempfiles'; $datadir = $msagdir . '/data/SAG_MSAG/';

I receive the following errors...

Global symbol "$msagdir" requires explicit package name at parse_zip.p +l line 16. Global symbol "$tempdir" requires explicit package name at parse_zip.p +l line 17. Global symbol "$datadir" requires explicit package name at parse_zip.p +l line 18.

Where have I gone wrong and what is the diff. between a global and local variable in a script?

Thanks-
ep

Edit 2001-05-08 by tye

Replies are listed 'Best First'.
Re: Global vs. Local
by azatoth (Curate) on Mar 08, 2001 at 23:43 UTC
      Sounds like you need to stick my before every variable.
      when you are using strict (which you always should), variables must be declared this way.

      <pedant>
      Well, that's not strictly true. When using strict you must either pre-declare variables or use their fully qualified names.

      You can pre-declare lexical vaiables using my or package variables using use vars. You can also use our if you're using Perl 5.6 or later.

      You can use package variables without pre-declaring them by giving them a fully-qualified name, e.g. $main::scalar, @main::array or %main::hash. These can also be abbreviated to $::scalar, @::array and%::hash.
      </pedant>

      --
      <http://www.dave.org.uk>

      "Perl makes the fun jobs fun
      and the boring jobs bearable" - me

Re: Global vs. Local
by arturo (Vicar) on Mar 08, 2001 at 23:51 UTC

    The document isn't completely accurate as of this moment, but you might check out (proposed)Scoping tutorial and attendant thread for some background.

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor