Wednesday, August 10, 2005

Great Perl Modules: part 1

In this series I will try to list perl modules, that are useful or nice.

I use CGI::Untaint for one of my website, and it is really useful. It helps untaint cgi parameters. Part of the usefulness of this module comes from the fact that you can extend the kinds of input it will untaint.

First I will show a little example:

use CGI;
use CGI::Untaint;

my $cgi = CGI->new;
my $params = CGI::Untaint->new($q->Vars);

# now you can extract variables.
my $number = $params->extract(-as_integer => 'id');

If a parameter can't be extracted by the extractor undef will be returned.

Without extensions this module can extract three types: printable, hex and integer. But on CPAN there are many more modules in CGI::Untaint namespace, that can extract URLs, dates, hostnames, isbn and postal codes.

If you need another extractor, you can always write one yourself.

0 Comments:

Post a Comment

<< Home