Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need explanation on some code to do with hashes and references. TY 1

Status
Not open for further replies.

FreshmenProgrammer

Programmer
Jan 16, 2006
42
CA
I was having trouble with understanding some code this is just a specific question but i have all the pieces of code from sparate files.

this is from a file called M responder.cgi.

my $auth_program = {
student => {
test => '/usr/local/oracle/oraappl/apps/scripts/mcds0020t.pm',
prod => '/usr/local/oracle/oraappl/apps/scripts/mcds0020.pm',
},

## Determine mode ('test' or 'prod')
my $mode = $q->url_param('mode');
$mode = 'prod' unless ($mode =~ /test/i);

## Determine student, employee or admin

my $user_type = $q->param('user_type');
$user_type = 'student' unless (($user_type =~ /employee/i) || ($user_type =~ /ad/i));


my $r = new M::Request();
$r->setAuthenticationProgram($auth_program->{$user_type}->{$mode});

the following code is from a file called M::Request();

sub setAuthenticationProgram
{
my $thing = 'authentication_script';
my $self = shift;
my $value = shift;

$self->{$thing} = $value;
return $value;
}

Do u see the line $r->setAuthenicationProgram($auth_program->{$user_type}->{$mode}); i don't really understand what its doing. Is it sending the user type and mode to the sub so that $self will equal student and $value will equal prod. I dont really understand whats happening here. Can you help me out with explaining this to me. thank you. I know its a reference to a hash but need some clarification on this code.. Thank you! This is my first day in the professional world after finishing school so whatever any one can answer would be greatly appreciated. Thank you!!
 


$r->setAuthenicationProgram($auth_program->{$user_type}->{$mode});

This is a instance method call.
The $r is the instance variable or reference.

The functions 'setAuthenicationProgram' first parameter is $r - the instance variable or object variable which is a reference.
The second parameter is
$auth_program->{$user_type}->{$mode}
which would be the value in the anonymous hash
based on the $user_type and $mode values

So basically you are calling the function by passing the
instance reference as the first argument and the value of hash as the second argument..

hope this helps..

Read up on hashes and object oriented programming in perl
 
this really smells like class-work, maybe not, but the odor is strong. ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top