Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with hash code...

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
I've pounded away at this code for god knows how long.. I want data from a form plugged into this given hash... its just leaving all the values blank and I'm racking my brain as to why... thanks for the help.

getInputo (\%inputo);

sub getInputo

{
my ($hashRef) = shift; #initialize the variable to hold the hash reference
my ($buffer) = ""; #initialize the buffer to hold info

$year = "year";

read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); #reads in the form info

foreach (split(/&/, $buffer)) #goes through the whole buffer where the input is stored
{
my ($key, $value) = split(/=/, $_); #splits up the input into the date and value
$key = decode($key); #sets the key and value to the decoded values
$value = decode($value);
$hashRef->{$key} = $value; #sets the key and value in the hash table
}
}

sub decode
{
$_ = shift; #the decode function which gets rid of all the stars which represent spaces
tr/+/ /;
s/%(..)/pack('c', hex($1))/eg; #convert any symbols out of hex back to symbols
return($_);
}
 
I think this is pretty much what you are trying to do in a more compact way:

[tt]
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@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))/eg;
$FORM{$name} = $value;
}
[/tt]

That stores all the values in the $FORM hash.

This method is somewhat looked down upon, and using the CGI.pm module is suggested to get form input (and a whole lot more!)

Check out the FAQ's in this forum or the Perl forum on how to use the CGI.pm module

Hope this helps.

-Vic vic cherubini
krs-one@cnunited.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash
====
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top