Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.jpl.nasa.gov (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: Perl beginner Message-ID: <1991May31.181659.28817@jpl-devvax.jpl.nasa.gov> Date: 31 May 91 18:16:59 GMT References: <1991May31.161535.2023@eci386.uucp> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 34 In article <1991May31.161535.2023@eci386.uucp> jmm@eci386.UUCP (John Macdonald) writes: : In article subbarao@phoenix.Princeton.EDU (Kartik Subbarao) writes: : |In article bobg+@andrew.cmu.edu (Robert Steven Glickstein) writes: : | : |Is it the case that the only way to find out the current : |>working directory is to do : |> : |> $cwd = `/bin/pwd`; : |> chop $cwd; : | : |In the case that your shell sets a CWD or PWD environment variable, then you : |can access it in perl by: : | : |$cwd = $ENV{'CWD'} (or PWD, or whatever). : : Be careful here - this only works if you will never have the Perl : script run from a program or script written for an interpreter that : does not keep $CWD correct. Tools should not be written to depend : on being run in a very specialized context that can't be validated, : unless you are absolutely sure that the will never be run from a : different context (or evolve into something that will be run from : a different context - there are many "temporary" programs around : whose ages are measured in decades). But also see pwd.pl in the Perl library. It uses the environment variable as a guess, but runs pwd if the guess is wrong. Thenceforth it can keep track of the current directory for you, as long as you call its chdir routine to do all your chdirs. My policy heretofore has been to drag my feet on adding routines that supply information that you only need once per process. Besides, it's good to force C programmers to use the toolbox occasionally. :-) Larry