scripting with perl

merlin's picture

They have: 410 posts

Joined: Oct 1999

well, i'm just learning perl (and i realized, i'm not alone... ). for getting used to the syntax, i'm trying to write a little script on my own (changing other scripts is doing well). it's a very simple one, here we go (it's only the 'problematic' part):

print << "EOM"
<form action="/cgi-bin/script.pl" method="POST">
<select name="id1" OnChange=submit()>
<option value="0">-------</option>
<option value="1">Value 1</option>
<option value="2">Value 2</option>
<option value="3">Value 3</option>
</select>
</form>
EOM
;;
if ($list{'id1'} eq NULL) {
print "error";
} else {
if ($_{'id1'} == "1") {
print "hi";
} else {
print "hello";
}
}

if "value 1" is selected, print 'hi', else print 'hello'.
so, how can i tell the script, it has to take the value of 'id1'? i thought i would do that with $list{'id1'}, but i realized, i'm not.

i think it's only a very little thing somewhere, and i'm sure you can help me out... thank you!

They have: 568 posts

Joined: Nov 1999

You have to make a form processor

try something like this

code:

   # 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))/eg;

      $FORM{$name} = $value;
   }
[/code]

then use $FORM{'id1'} to access it 
merlin's picture

They have: 410 posts

Joined: Oct 1999

thank you orpheus (for the 2nd time, are you something like my guardian angel? ).
i'll try that during my weekend... thank you!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.