I am trying to work my way through
perlboot. I thought I had got my head around
bless, but please don't take that for granted. At the point where it is first used, I have a problem. The code I have copied in from the tutorial is:
use strict;
{ package Animal;
sub speak {
my $class = shift;
print "a $class goes ", $class->sound, "!\n";
}
}
{ package Horse;
our @ISA = qw(Animal);
sub sound { "neigh" }
}
my $name = "Mr. Ed";
my $horse = \$name;
bless $horse, Horse;
$horse->speak;
I have added the first and last lines. This gives an error
Bareword "Horse" not allowed while "strict subs" in use at C:\Data\per
+lbootqry.pl line 17.
Execution of C:\Data\perlbootqry.pl aborted due to compilation errors.
Taking out Strict gives a different error:
a Horse=SCALAR(0x1829afc) goes neigh!
While this isn't a syntax error, it's not what I was expecting from reading the tutorial. Advice on what I'm doing wrong would be greatly appreciated.
It may be explained later in the tutorial, but something that bothers me is that all the sounds are subs. I would expect them to be scalars, but when I tried changing them I got nowhere. If all will become clear in due course, that's great, but if I'm heading for more confusion, please could someone point me in a more profitable direction?
Regards,
John Davies
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.