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

I declared my data directory as:

$dir1 = "E:\blah\blah\blah\data\"; (The paths were correct)

and got this error:

Global symbol "$dir1" requires explicit package name at E:\blah\blah\blah\parse.pl line 15.

Any ideas?

  • Comment on package for directory naming on NT systems?

Replies are listed 'Best First'.
Re: package for directory naming on NT systems?
by Fastolfe (Vicar) on Dec 22, 2000 at 00:53 UTC
    You have two problems:
    1. You are using strict without declaring your variables ($dir1). Put a 'my $dir1;' someplace that makes sense so that Perl knows what your variable is. See perldiag for more details about this message
    2. You are using backslashes in double-quotes, which will be interpolated. Either use single-quotes or escape your backslashes by doubling them: 'e:\whatever\whatever' See qq/q in perlop for details about how this works.
      Or use forward slashes. Paths with forward slashes work just fine in Perl on Windows.

      Update: I had written "forward quotes" when I meant to write "forward slashes".

        ...until you pass the file name to an external program and that program was written by Microsoft. Though I like to use regular slashes in Perl under NT and only rarely run into problems. A quick s#/#\\#g before calling any external program is all that is required.

                - tye (but my friends call me "Tye")
        Update: chipmunk fixed his post, so this is largely a useless followup.

        By 'forward quotes' are you talking about back-ticks (qx//)? I thought these interpolated just like qq// would..? I mentioned single-quotes, but I'm kind of confused as to how you could use this to build a pathname in a string.