Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: How do I make a constructor?

by merlyn (Sage)
on Apr 26, 2000 at 00:51 UTC ( #9106=note: print w/replies, xml ) Need Help??


in reply to How do I make a constructor?

The use of
  $class = ref($class) || $class;
is unneeded 90% of the time, and insufficient for 90% of the rest of the time.

If you want a clone method, use a clone or copy method on an instance. If you want another object of the same class as the first object, use

  my $two = ref($one)->new(@parms);
Which reduces our canonical simple constructor to:
  sub new {
    my $class = shift;
    my $self = { @_ };
    bless $self, $class;
Nice and simple.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2021-10-18 20:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (75 votes). Check out past polls.

    Notices?