[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Re: Current Directory (reprise)



At 22:49 -0400 07/12/1999, PBlase@aol.com wrote:
>In a message dated 7/12/99 10:04:33 PM, you wrote:
>
> >Under Unix
> >Perl, the current directory is not _necessarily_ the pace where the script
> >resides.
>
>Ok, so how _do_ you get/set the current directory?

The current directory "just is". You can get it from `pwd` for one 
thing. But the current directory moves around and its relationship to 
where the script (or the required files) is indeterminable.

The more appropriate question might be... how do you determine where 
the script is located so you can go up one level and require 
something?

We did this one in May (maybe I should put it into the FAQ?)

At 11:39 -0700 05/21/1999, Vicki Brown wrote:
>Under MPW (or Unix :), the "current directory" is where you are. The MacOS
>Finder analog (a pretty poor analog) would be the current window.  But of
>course, you move the mouse to launch a command, so the window moves. The
>MacPerl app emulates the "current directory" in a world that really doesn't
>possess the concept of "current directory".
>
>In Unix, or MPW, or any command line / shell environment, you (the user)
>stay in a particular directory and run commands by typing their names. The
>shell finds the command on the command path and launches it.  Even if the
>command is in a different directory (folder) than where you "are".
>
>So for example with MPW, I can sit in the shell window and ask "where am I
>now"
>
>  dir
>  mouse3*:Protected:Projex:MPW:MPW:vlb:
>
>I can look at the files and directories there
>
>  files
>  :seq2bio:
>  shell_relnote.pdf
>  Worksheet.vlb
>
>Note, no Perl scripts, no perl command here.
>The MPW perl command lives elsewhere:
>
>  which perl
>  mouse3*:Protected:Projex:MPW:MPW:Tools:perl
>
>even so, I can run it from "here" (my current working directory) and I
>don't have to "go" anywhere because the shell finds the program and
>launches it for me. It's one of the differences between a command interface
>and a click interface.
>
>  perl -e 'print `pwd`;'
>  mouse3*:Protected:Projex:MPW:MPW:vlb
>
>yep; that's where I am. Now suppose I have a Perl script that lives
>elsewhere
>
>  which foo.plx
>  mouse3*:Protected:Projex:MPW:MPW:Tools:foo.plx
>
>Here's the script:
>  Perl -Sx "{0}" {"Parameters"}; Exit
>  #!perl
>  print "working directory is ", `pwd`, "\n";  # working directory
>  print "script is in $0\n";                   # path to script
>
>The first line tells MPW perl to execute the script with Perl.  OK, the
>script is in the Tools folder (directory). I am in the vlb folder
>(directory).  Let's run the script:
>
>  foo.plx
>  working directory is mouse3*:Protected:Projex:MPW:MPW:vlb
>
>  script is in mouse3*:Protected:Projex:MPW:MPW:Tools:foo.plx
>
>So you can see that the "current directory" and the "place where the script
>resides" are NOT the same under MPW. They would be the same if I switched
>my current working directory to the Tools directory:
>
>  dir
>  mouse3*:Protected:Projex:MPW:MPW:Tools:
>
>  foo.plx
>  working directory is mouse3*:Protected:Projex:MPW:MPW:Tools
>
>  script is in :foo.plx
>
>Hmmm... $0 is not the full path to the script anymore. If I want to
>determine the full path to the script, I need to combine my knowledge of
>the current directory with $0... simply using $0 does not give me the full
>path. Using the current directory does not guarantee the location of the
>script.
>
>As long as you stick to the standalone Perl app, current directory will be
>the same as where the script is running (bacause that was how Matthias
>implemented current directory). But to be portable (to Unix, say, or to MPW
>MacPerl), then it is NOT always the case that current directory is where
>the script is. It's possible. It's not assured.
>
>- Vicki
>

-- --
        |\      _,,,---,,_       Vicki Brown <vlb@cfcl.com>
  ZZZzz /,`.-'`'    -.  ;-;;,_   Journeyman Sourceror: Scripts & Philtres
       |,4-  ) )-,_. ,\ (  `'-'  P.O. Box 1269  San Bruno  CA  94066
      '---''(_/--'  `-'\_) http://www.cfcl.com/~vlb  http://www.macperl.com

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org