in reply to Can't bless

choroba helped with the immediate problem, but maybe an example of common usage will help:

use strict; use warnings; package Pendulum; sub new { my ($class, %params) = @_; # Do interesting parameter validation here my $self = bless \%params, $class; # and other set up here. At this point you can call derived class +methods # as part of setup if you want using $self->methodName(); return $self; } package main; my $pit = Pendulum->new(Hz => 0.5);

Note in particular Pendulum->new(...) used to call the constructor

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Replies are listed 'Best First'.
Re^2: Can't bless
by perlfan (Parson) on Mar 27, 2021 at 16:10 UTC
    perlootut is a good start, in addition to the other docs mentioned herein. Actually I take that back, I may be misremembering how well done that was, but it doesn't even show a constructor using basic Perl.