Esteemed monks,
I am new to Perl and am studying my way (slowly) through Learning Perl Objects, References, and Modules by Randal L. Schwartz with Tom Phoenix.

In Chapter 10 (Object Destruction) in the section "Additional Instance Variables in Subclasses", while attempting to compile and execute the provided code, I have found a glitch (which in my notable inexperience I cannot remedy): Here is the code:
## Additional Instance Variables in Subclasses { package Animal; sub named { my $class = shift; my $name = shift; bless \$name, $class; } sub name { my $either = shift; ref $either ? $$either : "an unamed $either"; # see above s +ection for usage } sub speak { my $either = shift; print $either->name," goes ",$either->sound,"!\n"; } sub eat { my $either = shift; my $food = shift; print $either->name," eats $food.\n"; } sub DESTROY { my $self = shift; print "[",$self->name," has died.]\n"; } } { package Horse; our @ISA = qw/Animal/; sub sound { "neigh"; } sub DESTROY { my $self = shift; $self->SUPER::DESTROY; print "[",$self->name," has gone off to the glue facto +ry.]\n"; } } { package Sheep; our @ISA = qw/Animal/; sub sound { "baaah"; } } { package Cow; our @ISA = qw/Animal/; } sub feed_a_cow_named { my $name = shift; my $cow = Cow->named($name); $cow->eat("grass"); print "Returning from the subroutine.\n"; # $cow is dest +royed here } { package Barn; sub new { bless [], shift } sub add { push @{+shift}, shift } sub contents { @{+shift} } sub DESTROY { my $self = shift; print "$self is being destroyed...\n"; for($self->contents) { print " ",$_->name," goes homeless.\n"; } } } { package Barn2; sub new { bless [], shift } sub add { push @{+shift}, shift } sub contents { @{+shift} } sub DESTROY { my $self = shift; print "$self is being destroyed...\n"; while(@$self) { my $homeless = shift(@$self); print " ",$homeless->name," goes homeless.\n" +; } } } { package RaceHorse; our @ISA = qw/Horse/; ## extend PARENT constructor sub named { my $self = shift->SUPER::named(@_); print "DEBUG: $self\n\n"; $self->{$_} = 0 for qw/wins places shows losses/; $self; } sub won { shift->{wins}++; } sub placed { shift->{places}++; } sub showed { shift->{shows}++; } sub lost { shift->{losses}++; } sub standings { my $self = shift; join ", ", map "$self->{$_} $_", qw/wins places shows +losses/; } } my $racer = RaceHorse->named("Billy Boy"); # record the outcomes: 3 wins, 1 show, 1 loss $racer->won; $racer->won; $racer->won; $racer->showed; $racer->lost; print $racer->name," has standings of: ",$racer->standings,".\n";
When executing the code, I get this warning:
Not a HASH reference at notes_chap_10.perl line 303.
which is:
$self->{$_} = 0 for qw/wins places shows losses/;
in package RaceHorse.

Why am I getting this warning? I am new to most of the material in this book, and I am looking for some clarification, so I can understand the data movement here.

Thank you in advance for your help.

In reply to Hash ref question by paurus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.