Here's the way I would duplicate the functionality that you are trying to achieve:
#!/usr/local/bin/perl -wT use strict; use CGI qw/:standard/; # Geturl.pl # A little Perl script to read, decode and print the names # and values passed to it from an HTML Form thru CGI. # Get the HTML header, ender, define the page title. my $Title = "Get Information From a URL"; print header(), start_html ( -title => $Title ), h1( $Title ), hr(); # This gets the name of all of the form elements my @names = param(); # The param() function takes the name of the parameter and returns its + value foreach my $name ( @names ) { print "Name = $name, Value = " . param( $name ) . "<br>\n"; } print end_html;
Since you are new to Perl, there are quite a few issues that should be covered. If you want to see some of the basics, you can check out my online Web programming course. That should point you in the right direction. Also, you'll want to read about perl security.

Whenever you write a CGI program, you'll hear experienced programmers say the following:

Those are some of the basic issues. There's a lot of ground to cover. If you have questions after that, let us know.

Incidentally, the code snippet I wrote duplicated your code's functionality, but has a slight flaw. The following is a valid query string:

color=red&color=blue&color=some%20other%20value
Note that there are three values for 'color'. This is common. My code above will only return the first value entered. I did that to simplify the code. The following will correct for that (rough hack follows):
foreach my $name ( @names ) { my @values = param( $name ); print "Name = $name, Value(s) = " , join (',' @values) , "<br>\n"; }
That works because of the following:
# Assign param() to a scalar and you only get the first value my $value = param( $name ); # Assign param() to an array and you get all of the values my @values = param( $name );

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


In reply to (Ovid) Re: Beginning Perl and Forms by Ovid
in thread Beginning Perl and Forms by Stinger

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.