A
Art Werschulz
Hi.
I'm having a problem with "A horse of a different color", found towards the
end of the perlboot manpage.
Stripping things to the bone, here's my Perl file:
%<------%<--%<--%<---cut here---%<--%<--%<----------------------------
use strict vars;
{package Animal;
sub speak {
my $either = shift;
print $either->name, " goes ", $either->sound, "!\n";
}
sub new {
my $class = shift;
my $name = shift;
my $self = { Name => $name, Color => $class->defaultColor };
bless \$name, $class;
}
sub set_color {
$_[0]->{Color} = $_[1];
}
}
{package Horse;
use vars qw(@ISA);
@ISA = qw(Animal);
sub sound {"neigh"}
sub defaultColor { "brown" };
}
my $talking = Horse->new("Mr. Ed");
$talking->set_color("black-and-white");
%<------%<--%<--%<---cut here---%<--%<--%<----------------------------
The problem is that the $talking->set_color statement bombs with the error
msg "Not a HASH reference at foo line 19."
Of course, I looked for typos. I didn't see anything, but that may not
mean all that much.
I checked using Google, as well as the groups.gooogle.com archive of this
newsgroup. Of course, there's always the possibility that my search
criteria weren't good enough.
I also used perldebug. It didn't tell me anything too surprising:
%<------%<--%<--%<---cut here---%<--%<--%<----------------------------
main:21:5): {package Animal;
main:21:6): sub speak {
DB<1> b Animal::set_color
DB<2> c
Animal::set_color(21:36): $_[0]->{Color} = $_[1];
DB<2> x @_
0 Horse=SCALAR(0x8059ee8)
-> 'Mr. Ed'
1 'black-and-white'
DB<3> x @_[0]
0 Horse=SCALAR(0x8059ee8)
-> 'Mr. Ed'
DB<4> x @_[0]->{Color}
Not a HASH reference at (eval 5)[/usr/lib/perl5/5.8.0/perl5db.pl:17] line 2.
%<------%<--%<--%<---cut here---%<--%<--%<----------------------------
If anybody sees what I've missed here, I would greatly appreciate it. Many
thanks.
I'm having a problem with "A horse of a different color", found towards the
end of the perlboot manpage.
Stripping things to the bone, here's my Perl file:
%<------%<--%<--%<---cut here---%<--%<--%<----------------------------
use strict vars;
{package Animal;
sub speak {
my $either = shift;
print $either->name, " goes ", $either->sound, "!\n";
}
sub new {
my $class = shift;
my $name = shift;
my $self = { Name => $name, Color => $class->defaultColor };
bless \$name, $class;
}
sub set_color {
$_[0]->{Color} = $_[1];
}
}
{package Horse;
use vars qw(@ISA);
@ISA = qw(Animal);
sub sound {"neigh"}
sub defaultColor { "brown" };
}
my $talking = Horse->new("Mr. Ed");
$talking->set_color("black-and-white");
%<------%<--%<--%<---cut here---%<--%<--%<----------------------------
The problem is that the $talking->set_color statement bombs with the error
msg "Not a HASH reference at foo line 19."
Of course, I looked for typos. I didn't see anything, but that may not
mean all that much.
I checked using Google, as well as the groups.gooogle.com archive of this
newsgroup. Of course, there's always the possibility that my search
criteria weren't good enough.
I also used perldebug. It didn't tell me anything too surprising:
%<------%<--%<--%<---cut here---%<--%<--%<----------------------------
main:21:5): {package Animal;
main:21:6): sub speak {
DB<1> b Animal::set_color
DB<2> c
Animal::set_color(21:36): $_[0]->{Color} = $_[1];
DB<2> x @_
0 Horse=SCALAR(0x8059ee8)
-> 'Mr. Ed'
1 'black-and-white'
DB<3> x @_[0]
0 Horse=SCALAR(0x8059ee8)
-> 'Mr. Ed'
DB<4> x @_[0]->{Color}
Not a HASH reference at (eval 5)[/usr/lib/perl5/5.8.0/perl5db.pl:17] line 2.
%<------%<--%<--%<---cut here---%<--%<--%<----------------------------
If anybody sees what I've missed here, I would greatly appreciate it. Many
thanks.