in reply to OO modules
Perl assigns no special meaning to new.
bless associates a hash* with a class, allowing $o->method to work.
package Class; sub new { # Or any other name you want. my ($class) = @_; my $self = bless({}, $class); # $self->{...} = ...; return $self; } sub method { my ($self) = @_; #... } my $o = Class->new(); $o->method();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: OO modules
by BernieC (Pilgrim) on Dec 28, 2020 at 19:35 UTC | |
by ikegami (Patriarch) on Dec 29, 2020 at 17:43 UTC |