I am trying to use numbers passed from a form element to a script and use it to open a file for writing where the numbers passed are part of the file name.

<input type=hidden name=event value=123456>

I successfully pass the data to the script and can display it on the webpage, but everything goes wrong when I try to use it to open (create) a file for writing. Here is most all the code:

#!/usr/bin/perl -wT use CGI qw/:standard/; my $event = param('event'); my $commentUID = time(); my $newCOMMENT = param('newCOMMENT'); if ($newCOMMENT ne "") { open(AFH, ">> $event.txt"); print AFH "$commentUID\n"; close(AFH); open(BFH, ">> $commentUID.txt"); print BFH "$newCOMMENT\n"; close(BFH); }

The $commentUID.txt file is opened and written to just fine, but the form data passed to the script does not work at all. The most I could figure out is that the "." is being left out and 123456txt is trying to be opened...but all I get is an internal error. I have looked for a solution for several hours and cannot figure out how to do it. Please help.


In reply to open file using variable passed by form by michael.kitchen

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.