Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://263005]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2017-09-23 14:55 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (272 votes). Check out past polls.