M
Martin Kissner
Hello together,
I have read perldoc perlboot and tried to practice a little.
Now I have a problem with the (redueced) script below.
When I omit "use strict" i get the output of the final print statement
as expected.
With "use strict" I get the error:
Bareword "Sheep" not allowed while "strict subs" in use at
./sheep.pl line 23.
Execution of ./sheep.pl aborted due to compilation errors.
Line 23 is the second from last line.
I do not really know what the error means and I also do not know how to
change the script to make it work with "use strict".
Can anyone give me some explanation and/or point me to the applicable
section of the docs? perldoc -q "strict subs" was not helpful.
Thanks in advance and
Best regards
Martin
and here comes the code:
#!/usr/bin/perl
use warnings;
# use strict;
{ package Animal;
sub name {
my $instance = shift;
$instance->{Name}
}
sub color {
$_[0]->{Color}
}
}
{ package Sheep;
use vars qw(@ISA);
@ISA = qw(Animal);
sub sound { "baaah" };
sub default_color { "white" }
}
my $badsheep = bless { Name => "Evil", Color => "black" }, Sheep;
print "The sheep ",$badsheep->name," is ",$badsheep->color," and says ",
$badsheep->sound, "!\n";
I have read perldoc perlboot and tried to practice a little.
Now I have a problem with the (redueced) script below.
When I omit "use strict" i get the output of the final print statement
as expected.
With "use strict" I get the error:
Bareword "Sheep" not allowed while "strict subs" in use at
./sheep.pl line 23.
Execution of ./sheep.pl aborted due to compilation errors.
Line 23 is the second from last line.
I do not really know what the error means and I also do not know how to
change the script to make it work with "use strict".
Can anyone give me some explanation and/or point me to the applicable
section of the docs? perldoc -q "strict subs" was not helpful.
Thanks in advance and
Best regards
Martin
and here comes the code:
#!/usr/bin/perl
use warnings;
# use strict;
{ package Animal;
sub name {
my $instance = shift;
$instance->{Name}
}
sub color {
$_[0]->{Color}
}
}
{ package Sheep;
use vars qw(@ISA);
@ISA = qw(Animal);
sub sound { "baaah" };
sub default_color { "white" }
}
my $badsheep = bless { Name => "Evil", Color => "black" }, Sheep;
print "The sheep ",$badsheep->name," is ",$badsheep->color," and says ",
$badsheep->sound, "!\n";