On Fri, Nov 02, 2001 at 09:58:02AM +0800, feliciahk ([EMAIL PROTECTED]) said 
something similar to:
> From: "Carl Rogers" <[EMAIL PROTECTED]>
> To: "shalini Raghavan" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>;
> <[EMAIL PROTECTED]>
> 
> > open (MYFILE, ">>file_to_append_to.txt") or die "Can't open $!\n";
> >
> 
> Strange ! I sees the above openings in almost every script. What I could not
> understand is the reason for putting the die statement when the above
> statement will never "die". If the file is not there, it will create the
> file.
> 
> Is there a legitamate reason.

Sure is:

(root@perlguy):/usr/home/kevin>
# whoami
root

(root@perlguy):/usr/home/kevin>
# ls -la foo.txt
-rw-r--r--  1 root  sys  0 Nov  1 21:24 foo.txt

(root@perlguy):/usr/home/kevin>
# su kevin

(kevin@perlguy):/usr/home/kevin>
$ ls -la foo.pl
-rw-r--r--  1 kevin  kevin  73 Nov  1 21:25 foo.pl

(kevin@perlguy):/usr/home/kevin>
$ more foo.pl
#!/usr/bin/perl

open(FH, ">>foo.txt") or die "Bad boy! ($!)";
close FH;
(kevin@perlguy):/usr/home/kevin>

$ perl foo.pl
Bad boy! (Permission denied) at foo.pl line 3.


So, that is one reason. The person running the script may not have proper
permissions to append to a file, so the death of the script is legit. I sure
don't want 'kevin' appending to my /etc/passwd file :)

Cheers,
Kevin

-- 
[Writing CGI Applications with Perl - http://perlcgi-book.com]
I think you should leave it up to the parent, because not all parents want to
keep their children totally ignorant. 
        -- Frank Zappa (response to a question from Senator Hollings)

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to