⭐ 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.
|
---|
In Section
Seekers of Perl Wisdom