John Rambo John Rambo - 5 months ago 14x
Perl Question

Perl : what is my ($self, $firstName)

I am new to Perl language.

Can anyone explain the following subroutine, what is the difference between

my ($self, $firstName)
, it would be helpful if you can explain by relating it with Java:

sub setFirstName {
my ( $self, $firstName ) = @_;
$self->{_firstName} = $firstName if defined($firstName);
return $self->{_firstName};


my ( $self, $firstName ) = defines two variables and assigns them values from the list on the right hand side of the assignment operator.

$self->{_firstName} = treats the value of $self as a hashref and assigns a value to the _firstName key of the hash that it references.