in reply to current working dir is location of script?
Hi!
I think your main question has already been answered quite well, but here's a little more practical info for you in case you need to write a script that needs to read a config file from the same directory that the script is located, or something similar.
You can use the subroutine dirname() in the module File::Basename to get the script's location, using the perl special variable $0. You can then use the function chdir() to change your script's current working directory. Also, if you are want to make sure that $ENV{PWD} truly reflects your script's working directory, you can override perl's builtin chdir() with the one from the module Cwd, which will keep $ENV{PWD} up to date for you! Nifty, huh?
See the following code snippet for an example of how you might do this.
--#!/usr/bin/perl -lw use Cwd 'chdir'; use File::Basename; print "started in $ENV{PWD}"; chdir dirname $0; print "now in $ENV{PWD}";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: current working dir is location of script?
by halley (Prior) on Jul 31, 2003 at 12:57 UTC |