Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2015-11-25 09:27 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (672 votes), past polls