jvallee has asked for the wisdom of the Perl Monks concerning the following question:

I cannot get my script to save new files.

The path is correct. Another script uses /home/hampton1/data dir for writing out student.dat and it works fine.

The open<SDATA> statement is ok - I can see the data after stuffing it into an array.

However, no matter what I do, the new files are not being saved.

#!/usr/bin/perl use CGI; use File::Copy; use warnings; # define names of student reg info file,student count file and name of + js file to be sritten out $sdata="/home/hampton1/data/student.dat"; $scnt="/home/hampton1/data//student_count.dat"; $jscd="/home/hampton1/data/jscd.js"; # open existing student reg file open(SDATA,"$sdata")|| die("Could not open file: $!\n"); # Put file into array @line = <SDATA>; print @line; # confirms array contains contents of file close SDATA; # delete existing count & js file - so they can be to be recreated # test code unlink($scnt); unlink($jscd); # create file(> symbol is overwriting) open (SCNT,">$scnt"); close SCNT; # set all permissions chmod 0777, $scnt or die "Couldn't chmod $scnt: $!"; # create file(> symbol is overwriting) open (JSCD,">$jscd"); # print results to javascript file print JSCD "This is a test ()\n"; close JSCD; # set all permissions chmod 0777, $jscd or die "Couldn't chmod $jscd: $!";
I deleted all the processing code to see if it would simply create and save after I uploaded it.

the script works correctly on my PC with the files in the root dir and when they are in a subdir.

I made sure to upload in ASCII and set all permissions.

what am I overlooking?

Any help will be appreciated.

JV

Replies are listed 'Best First'.
Re: saving a file
by chromatic (Archbishop) on Oct 23, 2007 at 21:11 UTC
    what am I overlooking?

    Error checking:

    open( my $SCNT, '>', $scnt) or die "Cannot open '$scnt' for writing: $!\n";
Re: saving a file
by toolic (Bishop) on Oct 23, 2007 at 21:20 UTC
    You are still not using use strict; as recommended previously here and here.
Re: saving a file
by thezip (Vicar) on Oct 23, 2007 at 21:46 UTC
    • Where's strict???
    • Why are you using CGI?
    • "$sdata": double-quotes are unnecessary
    • Why do you unlink $scnt and $jscd, only to immediately open these files in clobber mode?
    • Perhaps a simple check like: (-e $sdata) || die qq(Dir "$sdata" doesn't exist...\n); would be beneficial
    • Your assignment for $scnt has a double-forward-slash in it

    Where do you want *them* to go today?
      Why do you unlink $scnt and $jscd, only to immediately open these files in clobber mode?
      Could be a broken attempt at the unixy "open, unlink, ..., close" temp-file pattern...

      ...but more likely, it's an unnecessary "cleansing" of the working directory before creation of those files ;)

      -David