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


In reply to Re: Problems writing to an external file by Purdy
in thread Problems writing to an external file by willick

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.