Disclaimer: I haven't written Perl or a major book on it so this answer is 
strictly IMHO, OTTOH and of course YMMV ;-P

boll <b...@sonic.net> asked:
> I would like to use this program in several places to display images
> from other directories, so that one URL might display a random image
> from the 'vegetables' directory, and a different URL would call the
> same program but display an image from the 'fruits' directory.

You can tack on so-called "GET" parameters to an URL by adding pairs of
"?key1=value1" [ "&key2=value2 ... [ "&keyn=valuen" ] ] 

Keys and values have to use a special encoding scheme for certain
"special" characters, see for example 
http://en.wikipedia.org/wiki/Percent-encoding

In your code, you can query these parameters using the param() method of
CGI.pm, like this:

my $q = new CGI;

my $key1 = $q->param('key1');

Keep in mind that people might call your script without a parameter or that 
they might try to hand-craft a value in order to exploit your code, so always 
validate your input and always provide a sane default value.

For example if you had a parameter like image category, you'd probably only 
want to allow numbers and lower case letters:

# make sure that your CGI parameter is clean
my( $img_category ) = ( $q->param('category') =~ m/^([a-z0-9]+)$/ );

# default for bad/missing parameter
$img_category ||= 'flowers';

Selecting the image based on a given category is left as an exercise for the 
reader. Hint: you might  want to extend the format of the image file list to 
include a "category" column.

HTH,
Thomas

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to