Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Things every perl programmer should know?

by hardburn (Abbot)
on Jun 04, 2003 at 14:34 UTC ( #263005=note: print w/ replies, xml ) Need Help??


in reply to Things every perl programmer should know?

My CGIs have a set_params() subroutine which returns a hash of all the paramters I want (I used to set global variables, but I kicked myself of that habit). Orginally, I did this one param at a time:

sub set_params { use CGI qw(:standard); my %params; $params{param1} = param('param1') || ''; $params{param2} = param('param2') || ''; $params{param3} = param('param3') || ''; # Dozen more lines of that return %params; }

Now I keep a constant global array named @FIELDS which contains a list of all the fields I want and put them together with map:

my @FIELDS = qw(param1 param2 param3 . . . ); sub get_params { use CGI qw(:standard); return map { $_ => param("$_") || '' } @FIELDS; }

You can remove the return in the above, but I kept it in this example for clarity.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

Note: All code is untested, unless otherwise stated


Comment on Re: Things every perl programmer should know?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://263005]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2015-07-03 13:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (53 votes), past polls