You are viewing a plain text version of this content. The canonical link for it is here.
Posted to asp@perl.apache.org by Philip Mak <pm...@aaanime.net> on 2001/07/07 14:39:11 UTC

Shorter way of getting form variables?

Is there a more efficient way of doing this:

my $type = $Request->Form('type');
my $login = $Request->Form('login');
my $password = $Request->Form('password');
my $SOME_VARIABLE = $Request->Form('SOME_VARIABLE');
etc.

I like to set these to real variables so that they are easier to type
later on in my code, but declaring them like that is always a pain.

I thought about doing something like:

for (qw(type login password)) {
  $$_ = $Request->Form($_);
}

but that interferes with UseStrict.

Or am I approaching this problem all wrong?


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: Shorter way of getting form variables?

Posted by Joshua Chamas <jo...@chamas.com>.
Philip Mak wrote:
> 
> Is there a more efficient way of doing this:
> 
> my $type = $Request->Form('type');
> my $login = $Request->Form('login');
> my $password = $Request->Form('password');
> my $SOME_VARIABLE = $Request->Form('SOME_VARIABLE');
> etc.
> 
> I like to set these to real variables so that they are easier to type
> later on in my code, but declaring them like that is always a pain.
> 
> I thought about doing something like:
> 
> for (qw(type login password)) {
>   $$_ = $Request->Form($_);
> }
> 

What I like to do is:

use vars qw( $Form )
sub Script_OnStart { $Form = $Request->Form };

Then I can do:

 my $type = $Form->{type};

> Or am I approaching this problem all wrong?
> 

Last time someone mentioned what you wanted to do, 
which is supposedly PHP like, on the modperl list,
lots of the resident experts went crazy about namespace
pollution, which is a good thing to consider, but 
short aliases can be extremely useful, so if you really
want to do what you are suggesting above, go for it, 
and get around the use strict stuff with the right
eval like:

  eval "\$$_ = \$Request->Form('$_')"

Also, if you are tired of typing ->, the above suggestion
could be to create a hash like Embperl...

  %fdat = %{$Request->Form};

so then you could $fdat{'type'}

--Josh
_________________________________________________________________
Joshua Chamas                           Chamas Enterprises Inc.
NodeWorks <- Web Link Checking          Huntington Beach, CA  USA 
http://www.nodeworks.com                1-714-625-4051

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org