Re: File creation issue

2004-12-24 Thread Sherm Pendley
On Dec 23, 2004, at 11:27 PM, Adam Butler wrote:
For some reason, when I try to use the open() function to create a new 
file,
it doesn't work.
We can only guess why it doesn't work - but Perl can tell you for 
certain:

open(TEST, ">test.txt") or die "Could not open test.txt: $!";
sherm--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


Re: File creation issue

2004-12-24 Thread Adam Butler
Hi,

What it's doing is opening the file for reading, and if the file doesn't
exist it creates it.  I uploaded it to my domain and it worked fine there,
so it's something wrong locally.

Here's the code just so you can see what I had:

Open(GAMELOG, "$file");
@entries = ;
close(GAMELOG);

Thanks for your help.
Adam

On 12/24/04 9:36 AM, "Conrad Schilbe" <[EMAIL PROTECTED]> wrote:

> First thing you should do is get perl to tell you why it can't open the file:
> 
> open(FH, "/path/to/file") || die "$!\n";
> 
> Most likely it's a permission problem - die "$!\n" will report something like:
> "Permission denied" - You do not have permission to open the file.
> "No such file or directory" - File does not exist or path to file is wrong.
> 
> Are you trying to append to a file or write over it or just read it?
> 
> To append to a file open it like this:
> 
> open(FH, ">> /path/to/file") || die "$!\n";
> 
> To overwrite the file:
> 
> open(FH, "> /path/to/file") || die "$!\n";
> 
> To simply read from the file:
> 
> open(FH, "/path/to/file") || die "$!\n";
> 
> 
> Cheers!
> 
> -- cs



Re: File creation issue

2004-12-24 Thread John Delacour
At 12:03 pm -0600 24/12/04, Adam Butler wrote:
What it's doing is opening the file for reading, and if the file doesn't
exist it creates it
Open(GAMELOG, "$file");
@entries = ;
close(GAMELOG);
You've had your answer. in your script 'Open' means nothing and the 
file won't be created even if you use 'open'.

#!/usr/bin/perl
chdir "/tmp";
$log = "game.log";
open LOG, ">$log" or die $!; # --->   >  !
print LOG "success !";
close LOG;
open LOG, $log;
for () { print };
Make it a rule NEVER to open a filehandle without testing.
JD


Re: File creation issue

2004-12-24 Thread Adam Butler
I forgot to mention that $file is set via a form.  On first run of the
script, it prints a form to the browser asking for a file name, which you
enter, and then it's submited and sent to the script.  The way I understood
it, when open tries to open a file that doesn't exist, it creates it.
Thanks,

Adam

On 12/24/04 12:15 PM, "John Delacour" <[EMAIL PROTECTED]> wrote:

>> Open(GAMELOG, "$file");
>> @entries = ;
>> close(GAMELOG);
> 
> You've had your answer. in your script 'Open' means nothing and the
> file won't be created even if you use 'open'.
> 
> 
>#!/usr/bin/perl
>chdir "/tmp";
>$log = "game.log";
>open LOG, ">$log" or die $!; # --->   >  !
>print LOG "success !";
>close LOG;
>open LOG, $log;
>for () { print };
> 
> 
> Make it a rule NEVER to open a filehandle without testing.
> 
> JD



Re: File creation issue

2004-12-24 Thread Conrad Schilbe
On Thursday 23 December 2004 11:27 pm, Adam Butler wrote:

> For some reason, when I try to use the open() function to create a new
> file, it doesn't work.  It will open a pre-existing file just fine, but if
> you enter a file that doesn't exist, instead of creating a new one it
> simply does nothing.

First thing you should do is get perl to tell you why it can't open the file:

open(FH, "/path/to/file") || die "$!\n";

Most likely it's a permission problem - die "$!\n" will report something like:
"Permission denied" - You do not have permission to open the file.
"No such file or directory" - File does not exist or path to file is wrong. 

Are you trying to append to a file or write over it or just read it?

To append to a file open it like this:

open(FH, ">> /path/to/file") || die "$!\n";

To overwrite the file:

open(FH, "> /path/to/file") || die "$!\n";

To simply read from the file:

open(FH, "/path/to/file") || die "$!\n";


Cheers!

-- cs