Re: [MacPerl-Modules] writing file in wrong directory
[email protected] (Thomas Wegner) Tue, 22 Oct 2002 10:08:59 +0200
| Newsgroups | perl.macperl.modules |
|---|---|
| Message-ID | <p04320401b9dab261194e@[149.225.70.152]> |
At 23:02 Uhr -0700 21.10.2002, Mark Wheeler wrote:
>Hi all,
>
>Here is a quick one that confuses me. I am trying to open one file in the
>cgi-bin directory, modify it's contents, then write the altered file to a
>completely different directory (up one directory, then into another
>directory). Here is the script:
>
>----------------------------
>
>
>sub createpage {
>
>open (GETFILE, "<$pathtotemplatepage") ||die " $!"; # open .html template
>@contents=<GETFILE>; # read contents into array
>$linenum=0;
>close (GETFILE);
>$lastline=$#contents;
>for ($last=0; $last<$lastline+1; $last=$last+1) {
> $contents[$last]=~s/:username:/$username/; #change contents
> }
>open (WRITEPAGE, ">../clients/client1.html"); # write file to new directory
>print WRITEPAGE @contents;
>close (WRITEPAGE);
>
>}
>
>
>----------------------------
>
>Here is what I get. The original file (the .html template) is read fine,
>altered fine, and written fine, except for two things which I think are
>connected. The final file that is written, is written to the cgi-bin
>directory (where the script is run), not the "clients" directory AND, the
>name of the file is not "client1.html", but rather "../clients/client1.html"
>
>What am I missing? Any help would be appreciated.
>
>Mark
You are on Mac OS Classic, right? So, one directory up and then down
into the 'clients' directory would be
"::clients:client1.html"
Here's a brief reminder of the Mac OS Classic path specification rules:
The path separator is a colon ':', not a slash '/'. A full path
always begins with a volume name. A relative pathname on Mac OS
Classic must always begin with a ':', except when specifying a file
or directory name in the current working directory, where the leading
colon is optional. If specifying a volume name only, a trailing ':'
is required (otherwise its optional, but should be used to
distinguish file from directory paths).
The current directory is denoted by ':', one directory up would be
'::', two directories up would be ':::' and so on.
Btw, this list is for discussion about modules, not general (Mac-)
Perl questions. So your question is better suited for the
<[email protected]> mailing list (or maybe the
<[email protected]> list).
HTH,
Thomas.