Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Problems writing to an external file

by Purdy (Hermit)
on Nov 13, 2001 at 18:52 UTC ( #125055=note: print w/replies, xml ) Need Help??


in reply to Problems writing to an external file

Trying to understand your purpose and I believe you may want to check out the HTML::Template module from CPAN. With it, you can create a "surround" (or template) file and pinpoint exactly where you want your $guidelines to go and then write the merged file where-ever you want. It looks like that's where you want to go since you're also reading in the filename, but not doing anything with it (yet). :)

Code for the template ($Bin/myfilename.TMPL):

Here are my guidelines: <TMPL_VAR NAME=GUIDELINES>

Then here would be the code for your CGI script:

# pre: $guidelines is defined, HTML::Template is installed # in your @INC and you have write privs to $filename use HTML::Template; my $template = HTML::Template->new ( filename => "$Bin/myfilename.TMPL" ); $template->param ( GUIDELINES => $guidelines ); # now you can either print the template to STDOUT or a filehandle # Option #1 (overwriting your .cgi file) open ( TEST, ">$filename" ); print TEST $template->output; close ( TEST ); # Option #2 (printing it to STDOUT - if to a Web browser, # make sure you've already sent the Content-type ahead of # this [next line]). print "Content-type: text/html\n\n"; print $template->output;

My apologies if I read this the wrong way - I just implemented HTML::Template myself and am enjoying it a lot. You will still need to work around your write privs issue if you want to write to a file (the previous responses will help you with that).

Jason

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://125055]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2019-11-19 13:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (95 votes). Check out past polls.

    Notices?