my $cgi = new CGI::Applicaton(...); $::global_var = $cgi; ... use $::global_var now anywhere ...
A variable like $::global_var is a fully-qualified name which is as close as Perl gets to global variables. It is equivalent to $main::global_var or to using our in package main:
... { package main; our $global_var; # same as $::global_var and $main::global_var ... }
You can create a tie interface if you want to access parameters like you did with a hash. See man perltie for more details. However, if you are writing new CGI applications, I wouldn't do this. Just extract parameters into simple variables if you need to use them more than once. A tie interface would allow you to use hash-like syntax for the following operations:
However, I would make sure it is really worth implementing because it will add complexity and degrade your application performance.print $hash{'key'} # same as print $webapp->param('key') $hash{'key'} = 3; # same as $webapp->param('key', 3);
If you really need to access the values as a hash, perhaps you can first extract all the CGI parameters to a hash like this:
our %hash; my @all_params = $webapp->param(); for my $p (@all_params) { $hash{$p} = $webapp->param($p); # } ... use %hash instead of calling $webapp->param(...) ...
In reply to Re: CGI::Application - alternative to using $self->param?
by pc88mxer
in thread CGI::Application - alternative to using $self->param?
by isync
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |