I have been instructed to expand on the website of my company, which uses perl scripts for the password protected area. I have little Perl experience. The following code is a script I wrote to add a user to database(which is actually just a text file). For some reason it won't write to text file. It is basically pulling a company code and password off of an HTML document and writing to a text file. Does anybody have any idea?
$UserDB = "datahere/UserDB.txt"; print "Content-type: text/html\n\n"; # Parse Form Contents &parse_form; # Add to user database &add_db; # display results &results; sub parse_form { if ($ENV{'REQUEST_METHOD'} eq 'GET') { # Split the name-value pairs @pairs = split(/&/, $ENV{'QUERY_STRING'}); } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { # Get the input read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the name-value pairs @pairs = split(/&/, $buffer); } foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/e +g; $Form{$name} = $value; } } sub add_db { open (FILE,">>$UserDB"); print FILE "$Form{'companycode'}\t"; print FILE "$Form{'password'}\t"; print FILE "\t\n"; close(FILE); } sub results { print "<html>"; print "<p>User Is Added</p>"; print "</html>"; }

In reply to Get Form Data/Write to Text File by ckluver

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.