Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: simplifying a CGI param request

by brian_d_foy (Abbot)
on Apr 07, 2006 at 17:24 UTC ( [id://541932] : note . print w/replies, xml ) Need Help??


in reply to simplifying a CGI param request

You don't need to store these in separate variables to use them. Just access the right thing with param when you need it:

foreach my $number ( 1 .. 25 ) { my $value = param( "q$number"); print "q$number: $value\n"; # or, without $value # printf "q%d: %s\n", $number, param( "q$number" ); }

If you really must import these, you could use an array (since you know they are ordered). You can fill in the element with index 0 with undef just to keep the numbers straight.

my @array = ( undef, map { scalar param("q$_") } 1 .. 25 );

If you really wanted these things in a variable, you can use the CGI::import function to do it all at once. It ends up creating package variables though, so it's usually not a good idea.

--
brian d foy <brian@stonehenge.com>
Subscribe to The Perl Review