>From "Learning PO, R & M", chap. 9:
Following along in the book (more or less faithfully) I now have:
#!/usr/bin/perl
use warnings;
use strict;
{ package LivingCreature;
sub new {
my $class = shift;
my $name = shift;
bless \$name, $class;
}
sub name {
my $either = shift;
ref $either
? $$either # it's an instance
: "an unnamed $either"; # it's a class, return generic
}
sub speak {
my $either = shift;
if (@_) { # something to say
my $dialogue = shift;
print $either->name, " says, \"$dialogue\"!\n";
} else {
print $either->name, " goes ", $either->sound, "!\n";
}
}
}
{ package Person;
our @ISA = qw(LivingCreature);
sub sound {
my @sound = qw(ahhh hmmm ohhh well ahem);
$sound[rand(5)];
}
sub sound2 { "..." }
}
And I then write:
my $john = Person->new("John");
print $john->speak("Hello");
This works fine except...
sputnik:~/-> ./animals
John says, "Hello"!
1sputnik:~/->
You'll see there is a "1" after the 'speak' routine's output (each time). I
can't see where the "1" comes from.
-Kevin
--
Kevin Pfeiffer
International University Bremen
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]