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

Open to and save from same file in CGI

by kb2yht (Acolyte)
on Apr 14, 2001 at 10:18 UTC ( [id://72558]=perlquestion: print w/replies, xml ) Need Help??

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

So The boss asked me to "make a fast forms based log book " And I set about the task using CGI.pm, and I've hit a , well starnge error, I open and refill the form with
open SAVE,"</tmp/report.sav"; my $page=new CGI \*SAVE ; close(SAVE);
do what I have to , and write a save out at the end using
open SAVE,">/tmp/report.sav"; $page->save(\*SAVE); close(SAVE);
This will not work, and I dont know why. However each part will work, If I comment out the save step at the end, the read works, like wise if i use
my $page= new CGI ;
the save function works, Plus , I dont get ANY errors.
How should I do this to make it work??
Thanks
Bill

Replies are listed 'Best First'.
Re: Open to and save from same file in CGI
by ColtsFoot (Chaplain) on Apr 14, 2001 at 11:16 UTC
    Without a little bit more of your code it's hard to say what's going wrong.
    The following works just fine for me
    #!/usr/bin/perl -w use CGI; open (IN, '</tmp/page.sav') or die qq(Failed to open input file); my $page; while (!eof(IN)) { $page = new CGI(IN); } close(IN); print $page->header(); print $page->start_html(); print $page->startform(-method=>'POST'); $page->param(-name=>'name', -value=>'ColtsFoot'); print $page->textfield(-name=>'name', -value=>'$name'); print $page->submit(-name=>'submit', value=>'Submit'); print $page->endform(); print $page->end_html(); open (OUT, '>/tmp/page.sav') or die qq(Failed to open output file); $page->save(OUT); close(OUT);
    The resulting file /tmp/page.sav looks like this
    name=ColtsFoot =
    Hope this gives you a clue.
Re: Open to and save from same file in CGI
by merlyn (Sage) on Apr 14, 2001 at 17:38 UTC
Re: Open to and save from same file in CGI
by sierrathedog04 (Hermit) on Apr 14, 2001 at 15:23 UTC
    When I had that problem it was because the webserver runs as some special user, perhaps 'web', and 'web' does not have the rights to write a file in the directory where it is attempting to write one.

    Look in your webserver's error logs to see if you are getting any kind of insufficient rights error messages.

Re: Open to and save from same file in CGI
by Mission (Hermit) on Apr 14, 2001 at 15:32 UTC
    One thing that I noticed right away was that you are opening SAVE for the read and the write. If they work independant of each other, then rename one of them. For example you could change the write/save (second one) like:
    open SAVEOut,">/tmp/report.sav"; $page->save(\*SAVEOut); close(SAVEOut);
    This is a shot in the dark, but I've seen stranger things happen. You'll notice in ColtsFoot's reply that there was an open IN and open OUT. I suggest you find a naming convention along those lines. BTW: Also I agree with Chady, a bit more information would be helpful. Since this is a shot in the dark, I might be completely off base and leading you astray.
    Either way, good luck and keep us informed.

    - Mission
    "Heck I don't know how to do it either, but do you think that's going to stop me?!!"
Re: Open to and save from same file in CGI
by Chady (Priest) on Apr 14, 2001 at 11:20 UTC
    This will not work.....I dont get ANY errors

    So what does not work?? I'm not getting any errors too and it seems correct, so maybe you can specify what (does not work) means, perhapps is your (do what I have to) between the reading and the saving what causing errors??


    He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-04-24 01:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found