Anyone interested: please comment on this code



I wrote the following code to manage information from a webform. I
would like to use it to continue learning about Perl and am hoping that
anyone who cares to might comment on this code's form and content. I
am not looking for it to be re-written (even where it may need to be)
but rather just for pointers and indications about where I might be
going wrong. (Just for information purposes, the overall aim of the
script is to create a string of code and it to the same directory this
script is in where it will call and be run by another application.)

The first part of the code in intended to read each of the form
elements' data and create a hash out of the re-formatted info.

The second part is intended to create a temporary, unique, txt file to
store the data of one of the fields. The last line has me a little
confused. I am not sure when this temporary file gets deleted (I want
it to be deleted when the entire script finishes running, after the
output is written).

The third part of the script is intended to write one of the values
from the hash (corresponding to a particular form field datum) to the
temporary text file just created.

The last part of the script takes two other values from the hash (again
corresponding to form field data), concatenate them with a reference to
the text file and then output that string to the same directory (where
it will be picked up and run by another application).

The code:

#!/usr/bin/perl

#===============================================================================
# modules utilized
#===============================================================================

use IO::File;
use POSIX qw(tmpnam);



my $method = $ENV{'REQUEST_METHOD'};

if ($method eq "GET") {
$text = $ENV{'QUERY_STRING'};
}

else { # default to POST
read(STDIN, $text, $ENV{'CONTENT_LENGTH'});
}


#perform first separation into individual form element:value pairs
my @value_pairs = split (/&/,$text);
my %form_results = ();

#five value pairs are sent --
#hash:hashid; pswd:password;lastDMCLI:after description;
#detDescrip:detailed description; firstDMCLI:first part of DMCLI


foreach $pair (@value_pairs) {
#separate each form element name and its corresponding value
($key, $value) = split (/=/,$pair);
#convert plus signs to spaces
$value =~ tr/+/ /;
#decode hex characters
$value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg;
$form_results{$key} = $value; # store the key in the results hash
}
#store the data in a hash called %FORM
$FORM{$name} = $value;


#===============================================================================
#create a txt file to write detailed Description
#===============================================================================

# try new temporary filenames until we get one that didn't already
exist
do { $descripTmpFilename = tmpnam() }
until $fh = IO::File->new($descripTmpFilename,
O_RDWR|O_CREAT|O_EXCL);

# install atexit-style handler so that when we exit or die,
# we automatically delete this temporary file --

END { unlink($descripTmpFilename) or die "Couldn't unlink
$descripTmpFilename : $!" }

#===============================================================================
#write detailed Description to txt file
#===============================================================================

open ($fh, ">$descripFiles")
print $descripTmpFilename $FORM{chdocDescription}

#===============================================================================
#create DMCLI with description file reference
#===============================================================================
# next line sets the MIME type for the output

print "Content-type: text/plain\n\n";

$dmcli =
$FORM{firstDMCLI}.'/cgi-bin/tempDescrip/'.$descripTmpFilename.$FORM{lastDMCLI}
print OUTPUT $dmcli

.



Relevant Pages

  • Re: reversing hash ?
    ... I have found one web site out there that uses a very similar script to ... digit of the second hash from the "encrypted" (I really don't want to use ... the first character of both are changed by the same ... For example, the first URL is 6 letters long, so ...
    (sci.crypt)
  • RE: Problem with LWP::UserAgent
    ... have an xml file that contains a list of URLs. ... hash and pass them as a parameter into the function that does LWP get. ... > assume your script is named net.pl, you can involve the debugger with: ...
    (perl.beginners)
  • Re: [SLE] Thunderbird stopped calling Firefox
    ... Jim Sabatke wrote: ... |> Hash: SHA1 ... Are you using the script or something ...
    (SuSE)
  • Re: Own module needs loaded module from main script
    ... If you think those results are odd, you haven't spent very long time ... in the beginning of every script / module. ... That loads the module *and* imports the %CONFIG symbol to package ... the hash is not *returned* by the subroutine. ...
    (comp.lang.perl.misc)
  • Re: strip_tags works, then it doesnt in an if/else.
    ... HTML tags in a form field without actually changing anything...I was ... I left off some of the script. ... alerting to the pressence of) non-ASCII characters, non alphanumerics, ...
    (comp.lang.php)