| Category: | CGIs |
| Author/Contact Info | Florian "octopus" Forster <octopus@13hackerz.de> |
| Description: | I do a lot of CGI programming and there for I really love using tools like ePerl or emb_perl. But there is one feature in PHP that I always missed in perl/cgi.pm: That all parameters automaticly get assigned to the according variables. (E.g. the variable $name should hold the parameter "name".) It might be that cgi.pm provides such an function, but I was too lazy to RTFM so I hacked that module. All it does is reading the parameters into the caller's namespace.. |
package import_params;
use CGI ':standard';
use strict;
my @all_params = param ();
my $caller_package = caller;
foreach my $prm (@all_params)
{
no strict 'refs';
my (@tmp);
@tmp = param ($prm);
if (scalar @tmp == 1)
{
${"${caller_package}::${prm}"} = $tmp[0];
}
elsif (scalar @tmp > 1)
{
@{"${caller_package}::${prm}"} = @tmp;
}
# You might want to remove the "elsif" part and
# run the code everytime. Then you have _all_
# parameters in that array.
}
1;
|
|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Automatic Parameters for CGIs
by chromatic (Archbishop) on Jan 18, 2001 at 11:10 UTC | |
by extremely (Priest) on Jan 19, 2001 at 06:08 UTC | |
by chipmunk (Parson) on Jan 19, 2001 at 21:33 UTC | |
by extremely (Priest) on Jan 20, 2001 at 12:08 UTC |