Newbie Post! Heads up! (file question) 
Author Message
 Newbie Post! Heads up! (file question)

 Ok, pardon the shroud of ignorance here and/or if this is a Frequently
Questioned Answer.....
when I (or you or we) say:

open(SOMEFILE,">disfile") || die "no can do"
open(TINCAN,"tincan") || die "tincan won't open"

 are the files (disfile and tincan) always assumed by perl to be in the
directory that the script is in? I'd think the answer is yes, unless
specified otherwise (as in /etc/passwd, /etc/aliases or by some variable).
 Is there ever a case when it's otherwise? Or am I fulla worms here? I'm
fairly new to perl, so again pardon my SOI.
 Emailed answer would be much appreciated, as our news server expires like
every 14 minutes or something...
 thanks in advance,


***************************************************************************
            For PGP public key, mail me with Subject:GET KEY
        For random Ambrose Bierce quote, Mail me with Subject: ambrose
       Support the anti-Spam amendment - Join at http://www.*-*-*.com/
      "Microsoft was invented by domestic terrorists.  Remember, it's
                     no longer an import industry."



Tue, 11 Jan 2000 03:00:00 GMT  
 Newbie Post! Heads up! (file question)

Jamie,

This is how I handle opening my files.  You do need the specific path:

$data = "/files/WWW/vhtdocs/boondoggle/area3/data.txt";
open(FILE,"$data");

Hope this helps.

Burt



Quote:

> Ok, pardon the shroud of ignorance here and/or if this is a Frequently
>Questioned Answer.....
>when I (or you or we) say:

>open(SOMEFILE,">disfile") || die "no can do"
>open(TINCAN,"tincan") || die "tincan won't open"

> are the files (disfile and tincan) always assumed by perl to be in the
>directory that the script is in? I'd think the answer is yes, unless
>specified otherwise (as in /etc/passwd, /etc/aliases or by some variable).
> Is there ever a case when it's otherwise? Or am I fulla worms here? I'm
>fairly new to perl, so again pardon my SOI.
> Emailed answer would be much appreciated, as our news server expires like
>every 14 minutes or something...
> thanks in advance,


>***************************************************************************
>            For PGP public key, mail me with Subject:GET KEY
>        For random Ambrose Bierce quote, Mail me with Subject: ambrose
>       Support the anti-Spam amendment - Join at http://www.cauce.org/
>      "Microsoft was invented by domestic terrorists.  Remember, it's
>                     no longer an import industry."



Tue, 11 Jan 2000 03:00:00 GMT  
 Newbie Post! Heads up! (file question)


Quote:

> Ok, pardon the shroud of ignorance here and/or if this is a Frequently
>Questioned Answer.....
>when I (or you or we) say:

>open(SOMEFILE,">disfile") || die "no can do"
>open(TINCAN,"tincan") || die "tincan won't open"

> are the files (disfile and tincan) always assumed by perl to be in the
>directory that the script is in? I'd think the answer is yes, unless
>specified otherwise (as in /etc/passwd, /etc/aliases or by some variable).
> Is there ever a case when it's otherwise? Or am I fulla worms here? I'm
>fairly new to perl, so again pardon my SOI.

Many systems (Unix and MS systems at least, I think) have a notion of a
"working directory" and a path.  If I'm "in" /dir/one when I call a script
then the system will look for the script down my search path and execute
it if it's found.  All relative file opens are done with respect to the
working directory, so opening "foo" will open /dir/one/foo whether the
script was found in the working directory or in some other place in the
search path.  Perl has the chdir call to change the working directory, and
absolute file names (e.g. /etc/passwd) don't use the working directory to
find the file.

Hope this helps,

Mike

--

http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41



Tue, 11 Jan 2000 03:00:00 GMT  
 Newbie Post! Heads up! (file question)

Quote:

> Subject: Newbie Post! Heads up! (file question)

Please check out this helpful information on choosing good subject
lines. It will be a big help to you in making it more likely that your
requests will be answered.

    http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post

Quote:
>  Ok, pardon the shroud of ignorance here and/or if this is a Frequently
> Questioned Answer.....

I'm puzzled. If you thought it might be in the FAQ, why didn't you check
before you posted?

Quote:
> when I (or you or we) say:

> open(SOMEFILE,">disfile") || die "no can do"
> open(TINCAN,"tincan") || die "tincan won't open"

>  are the files (disfile and tincan) always assumed by perl to be in the
> directory that the script is in?

No. They are normally assumed (by the _OS_) to be in the current working
directory. For more details, check out your system's docs about the cd
command and related operations. Hope this helps!

--
Tom Phoenix           http://www.teleport.com/~rootbeer/

Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



Tue, 11 Jan 2000 03:00:00 GMT  
 Newbie Post! Heads up! (file question)


Quote:
> This is how I handle opening my files.  You do need the specific path:

> $data = "/files/WWW/vhtdocs/boondoggle/area3/data.txt";
> open(FILE,"$data");

That turns out not to be the case. You don't necessarily need the full
pathname, although that's not a bad thing to include. (And the extra set
of double quotes doesn't help.) But, more importantly, you should always
check the return value from open, _especially_ when you're helping
somebody to learn how to program.

   open FILE, $data
        or die "Can't open '$data' for read: $!";

Hope this helps!

--
Tom Phoenix           http://www.teleport.com/~rootbeer/

Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



Tue, 11 Jan 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Newbie LWP Question on POST Method

2. question from newbie (more improved post READ FIRST)

3. newbie: lwp/post question

4. Passing objects around - newbie in over head

5. Two questions: 1)Erasing temporary files 2)post method

6. POST CGI - echo post data to a known file

7. Newbie Question : remove files named $files

8. perldoc page heading question

9. inserting at head of a file

10. LWP: doing a HEAD on FTP files

11. stripping garbage from head of file

12. Newbie Question: File Modification Date!

 

 
Powered by phpBB® Forum Software