in reply to Re: perl oo
in thread perl oo

OeufMayo: you have the right idea, but you're on the wrong track and are a bit confused about context.
my $class = @_;
The left side is a scalar, which means the array '@_' is being called in scalar context. As a result, $class will be set to the number of elements in @_.

Also, you want curly braces '{}' in the "my $self =" line to create the reference to the anonymous hash. The following should work:

sub new { my ( $class ) = @_; my $self = { user => $_[1], session => 4556, }; bless($self, $class); return $self; }
Putting the parenthesis around $class in the first line of the sub causes it to be evaluated in list context and grabs the first element of @_. There are still better ways to write that, but I'll leave it at that for now.

Hope this helps!

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.