Forum Moderators: coopster & phranque

Message Too Old, No Replies

verification subroutine

         

Davo1977

9:53 pm on Oct 8, 2008 (gmt 0)

10+ Year Member



I have experience programming in Javascript, and right now, I'm learning CGI scripting with perl and am making a little verifcation script (to verify if a user has submitted a valid username, password, etc...). What I'd like to do is put the entire verification process in a subroutine, named verify. I've been thinking of ways to do this, and right now what I'd like to do is pass a reference to a hash containing a set of keys and values

(eg key-> username value-> someusername)

The verify subroutine will then first look at a key, determine what the key's name is, and finally evaluate whether that key's value fits a certain regular expression.

I'm not asking anyone to write this entire script out, I would actually like to do that myself. What I do need is an example or explanation of how to pass a reference to a hash into a subroutine, and then how to access that hash's keys and values through the passed reference. I looked online for examples, but there weren't any specific enough to help me.

Thanks in advance to anyone, sorry if I rambled on too much!

phranque

2:33 am on Oct 9, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



this "reference" reference [perldoc.perl.org] might help.

essentially, if you have a %hash, you can use the backslash operator to create a reference, like:
$hashref = \%hash;

then pass the $hashref in the subroutine argument list and access values as $hashref->{'KEYVALUE'} or $hashref->{$keyref}