Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

saving dynamically generated files on server 3

Status
Not open for further replies.

baad

Programmer
Apr 10, 2001
1,481
RU
hi there

excuse me for posting a question, but i haven't managed to find answer myself yet..

now i am on
&

& here in faqs area & in search area.. i'm a bit lost & don't undersand anything any more X-) too much information at a time!! :(

what i wanna find is how could i save an information i got from user in a file on server?

to shed some light:
this forum is made (as i understand) this way:
i'm (a user) submitting this form (<FORM NAME=&quot;getquestion&quot; ACTION=&quot;submitpost.cfm?..)
then in the coldFusion's submitpost.cfm my question is being parsed & saved as a unique file that i can access from this forum, clicking a link with the subject..

so, my question is: HOW in the name of GOD can i do something very similar (not in CF, but preferably in Perl)

actually i'm not asking for a full desriptive answer, i'd like to find it myself, but i need a direction where i should keep digging.. now i'm getting tired of this search

thanks for your time :)
Victor
 
please see faq452-653 about the basics to CGI stuff. Once you see how to submit and catch information from a form, you will be well on your way.

Please don't worry about asking easy questions. But, please also do not be put off by being asked to take a look at the faq. I have answered this question many times, and the faq keeps me from having to retype it. I hope it is helpful. Please ask further after viewing the faq. Please use descriptive titles and check the FAQs.
And, beware the evil typo.
 
hi
it was my first action to save those faqs..
but don't worry, i'm not feeling offended or something, i do the same when i know that question was answered in faqs area..
but that's the way i'm searching for something: first i save EVERYTHING i find that looks like relative to the needed subject & then i'm learning all of it, deleting useless & saving what i'd find usefull..

you see, i haven't found something of what i was after in your faq, sorry..

i know how to generate html file in answer to any form submittion, using information from user (i think that is what your faq about) but what i want is to save this document on the server, for not to fill & submit that form again & again, but just click on some link (to that file) & look, what is written there.. hears pretty simple, but i'm stuck..

have i shed some light on my problem or am i missing something?

may be some modules i should use for these porposes, some usefull links? anything?

thanks again
& sorry if i missed something from faqs.. Victor
 
If you are simply trying to catch a web page and save it, then use LWP. The following will retrieve the 'text' of the web page and save it to disk.

Code:
#!/usr/local/bin/perl
use LWP::Simple;

$uri = '[URL unfurl="true"]http://www.addcritic.com/';[/URL]
$started = time;

# this will get the HTML text
$content = get($uri);
print &quot;Got content\n&quot;;

open(OPF,&quot;>some_output_file_name&quot;) or die &quot;Failed to open OPF, $!\n&quot;;
print OPF &quot;$content&quot;;
close OPF;

If your dynamically generated page requires some inputs, you might be able to supply them in your uri string.

Code:
$uri = &quot;www.server.com/cgi-bin/prog.cgi?input1=value1&input2=value2&quot;;

HTH Please use descriptive titles and check the FAQs.
And, beware the evil typo.
 
Vituz

If you are trying to save the parameter settings, then this can be simplified by the CGI perl package. Try 'perldoc CGI' for more information. An extract from this documentation:

Code:
     Here's a short example of creating multiple session records:

        use CGI;

        open (OUT,&quot;>>test.out&quot;) || die;
        $records = 5;
        foreach (0..$records) {
            my $q = new CGI;
            $q->param(-name=>'counter',-value=>$_);
            $q->save(OUT);
        }
        close OUT;

        # reopen for reading
        open (IN,&quot;test.out&quot;) || die;
        while (!eof(IN)) {
            my $q = new CGI(IN);
            print $q->param('counter'),&quot;\n&quot;;
        }

Cheers, NEIL
 
thanks for replyes, but all i wanted to know is what module works with files (if i needed such a module) to be exact - very silly question - how to create (but not open) a new file that than could be saved on server

sorry guyz for spending your time on me, stars for yor help :) becouse you really helped me (i'm in the very begining of cgi, & everyhing looks pretty helpfull for me :) Victor
 
The normal approach to saving a file to disk is:
1 - open a new file
2 - write content to that new file
3 - close that file - done

# Example of opening a new file
$file_name = 'myFile.txt';
open(NEW,&quot;>$file_name&quot;) or die &quot;Failed to open $file_name, $!\n&quot;;


# print content to that file throught its handle (NEW)
print NEW &quot;Some text to go into the file.\n&quot;;

# close the new file and your done
close NEW;

Obviously, this is over simplified. You would probably want
more content that I show here. The examples above
in this thread show the gathering of content from web pages.

HTH Please use descriptive titles and check the FAQs.
And, beware the evil typo.
 
opening, creating and writing to a file in PERL are built in commands of PERL.

As in goboating post above the file you open is giving a file handle that PERL refenences it with.

open (NEW,&quot;>$filename&quot;) or die &quot;Failed to open $filename, $! \n&quot;;

&quot;NEW&quot; in this statement is a filehandle

take that filehandle and reference it in the following statments

print NEW &quot;some infomation&quot;;

the &quot;>&quot; sign in the above statement is a variable

it comes in different form like >>, <, +>> each will give you differnt functions to that file.

&quot;>&quot; will open for writing and create if doesnt already exits
but will not allow explicit appending of file and will clobber existing data if written to.
&quot;>>&quot; will open for writing, appending and create if does not exit, no clobbering of data
&quot;+>>&quot; will open for read, write, append and create if doesnt exist

always close the file ASAP
use this

close new;
 
yea, thanks, i've already handled it
thanks anyway, good answer :)

Victor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top