in reply to Re: hash reference to itself
in thread hash reference to itself

There is no object here, just class calls which might as well be package calls.

print MyPkg::name(), $/; MyPkg::print();

Replies are listed 'Best First'.
Re^3: hash reference to itself
by VinsWorldcom (Prior) on Aug 02, 2016 at 20:01 UTC

    You're right. Is this better?

    #!perl use strict; use warnings; package MyPkg; sub new { my ($self, $name) = @_; my %hash = ( name => $name ); return bless \%hash; } sub print { my $self = shift; print "name: " . $self->{name}; } package main; my $obj = MyPkg->new('foo'); $obj->print();

      Yeppers. Though I am not a fan of anything but a view layer (this would be main:: implicitly here) doing output so print embedded in methods/subs is, to me, code smell. I understand it's convenient for examples but it can rub off on newbies as a good practice.