CGI Paramater Validation Simple Validation 6 of 32 : [PREV] [NEXT]

Quick & Dirty

If your names not on the list, you're not coming in!

my %rules = ( action => qr/^[\w\.\-]+$/ };

foreach my $name ($cgi->param()) {
next unless($rules{$name});
  my $value = $cgi->param($name);
  next unless($value =~ $rules{$name});
  $cgiparam{$name} = $value;
}

Much better. Now we just expand the rules to include other regular expressions and reference our values by referencing the name in the %cgiparam hash.

To improve on this we could create a configuration file with all our rules and load them dynamically.


© 2003 Barbie barbie@missbarbell.co.uk Home http://birmingham.pm.org/