#!/usr/bin/perl -w
#
# Here is a CGI example of using a regexp to parse a query string,
# when you're not sure exactly what will be in the query string
# Put it in you web space, and call it with
# http://host/script?param_1=this¶m_2=that&the_other=doesntmatchth
+emask
# or call it with ?error=HelloWebMaster if you want to fill the error
+log with garbage
#
use CGI qw( :standard :HTML );
# set slay typos
use strict;
# read in the CGI params
my $object = new CGI();
# print our HTML header
print header(),h1( "params: " );
my $key;
# set our variable mask. This part gets thrown out.
# At makeyourbanner.com, I use more than one pattern,
# so that I can determine the number of text areas and style settings
+dynamically.
# in CGI programming, this is very handy if you are designing a backen
+d,
# and don't have advanced knowledge of how the front end will call it.
my $mask = "param_";
foreach $key ( $object->param() ) {
if ( $key =~ /^($mask)(.+)/ ) {
#found a parameter, print it out
print "<P>param $2=", $object->param( $key ), "</P>";
} elsif ( $key =~ /error/i ) {
#found error flag, print error to the appache logs (you ARE us
+ing apache, right?!)
print STDERR "error: found $key=", $object->param( $ke
+y ), " in $0\n";
}
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|