in reply to Re: lib
in thread lib

Okay

One other thing, I want to open this file (which is in the current directory) but it wont let me unless i type in the full path from root.

open(INPUTFILE, "<postcode.txt")

I have to do this

open(INPUTFILE, "</WEBDEV/cgi-bin/postcode.txt")

Surely the perl knows to look from the existinf directory (eg ".")

Replies are listed 'Best First'.
Re: lib
by kal (Hermit) on Apr 11, 2001 at 15:47 UTC

    If you're running it as a CGI you don't necessarily know what the current directory is. Try doing a print `pwd`; to see where the script actually is.

    Usually, with things like file paths, it can be useful to make a configuration variable that holds this stuff in, so when you open you do something more like open (INPUTFILE, "<$root/postcode.txt");. $root can be a variable set at the top of the file, read in from a configuration file, etc.

      Seems like a lot of trouble to go to - opening a new shell just to get the current directory. Particularly when Perl has a standard module to do just that.

      use Cwd; print cwd;
      --
      <http://www.dave.org.uk>

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

        Or even a prefined var ;-)
        print $ENV{'PWD'};

        "Only Bad Coders Badly Code In Perl" (OBC2IP)