Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

(Ovid - quick fix to your new constructor) Re(2): perl oo

by Ovid (Cardinal)
on Jan 15, 2001 at 23:48 UTC ( [id://52030]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-19 15:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found