Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

write to local files? and why does strict bugger this online but not locally?

by jerrygarciuh (Curate)
on Sep 12, 2001 at 23:51 UTC ( #111999=perlquestion: print w/replies, xml ) Need Help??

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

I have 2 questions about this script (which now works yay!!) First, is it possible for me to write to a local file ie on my hard drive)? The script runs without error but does not write to the file. Second, despite yielding no errors in local tests, once online the script only works if I remove the strict pragma. I read strict again just now but I don't see why it runs locally with strict and online it gives Internal Error (500).
TIA
jg
#!/usr/bin/perl -w use strict; use warnings; use diagnostics; my @words = qw(baloney has a first name); open (TEXTFILE,">>menu.txt") || die "where's the damn file? : $!"; print TEXTFILE "My baloney has a first name."; close (TEXTFILE) || die "close damn you : $!"; print "Content-type: text/html\n\n"; print "<HTML> \n"; print "I did it all for you. \n";
  • Comment on write to local files? and why does strict bugger this online but not locally?
  • Download Code

Replies are listed 'Best First'.
Re: write to local files? and why does strict bugger this online but not locally?
by ncw (Friar) on Sep 13, 2001 at 00:09 UTC
    Firstly, yes it is possible to write to a local file. I tried your program and it worked creating menu.txt.

    If the file didn't get created then it is probably being created somewhere else. Put a

    use Cwd; print cwd();
    Into your program to see where it thinks the current directory is, then look there for menu.txt

    Secondly - check the version of perl between your local machine and the remote machine.

    perl -V
    Will tell you, or if you don't have shell access just run that from a system command.

    If it is < perl 5.6 then use diagnostics won't work which is a possibly explanation.

      If it is < perl 5.6 then use diagnostics won't work which is a possibly explanation.
      ? The diagnostics module has been around since 1995, and only requires 5.001. The warnings module is the one that needs 5.6. Which, of course, doesn't explain why removing use diagnostics fixed the problem for jerrygarciuh. Unless s/he actually removed the use warnings line....

      Yikes!! It sure was being created in the local tests, in C:\Windows!!! It would have overwritten another file had I been using an unwise name... Correct? How do you tell a script to ask before overwriting? Thx for both answers, you were correct on both counts, server is v5.0 and removing diagnostics corrected problem!!
      jg
Re: write to local files? and why does strict bugger this online but not locally?
by ghost (Beadle) on Sep 13, 2001 at 04:16 UTC
    It sounds like the user for your CGI (nobody on Unix, IUSER_GUEST on NT, usually) doesn't have access to write to the directory. Also, you probably want to use a chdir or specify a directory for the file.

    One of your "die" messages probably caused the 500 error. Include use CGI::Carp qw(fatalsToBrowser); or add some code to print a header to see your "die" messages in CGI.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://111999]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2022-05-16 22:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (64 votes). Check out past polls.

    Notices?