Problem with bless

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
 
P

Paul Lalli

Martin said:
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".

Offhand, I'd say you have an error on line 23. Probably involving
using a bareword, which isn't allowed when you've enabled 'strict
subs'.

Of course, it's impossible to more precise without seeing the code to
which you're referring.
Can anyone give me some explanation and/or point me to the applicable
section of the docs? perldoc -q "strict subs" was not helpful.

perldoc strict

Paul Lalli
 
M

Martin Kissner

Paul Lalli wrote :
Of course, it's impossible to more precise without seeing the code to
which you're referring.

I'm sorry, I forgot to paste the code. I superseded my first post.
Here is 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";
 
M

Martin Kissner

Paul Lalli wrote :
Offhand, I'd say you have an error on line 23. Probably involving
using a bareword, which isn't allowed when you've enabled 'strict
subs'.

Of course, it's impossible to more precise without seeing the code to
which you're referring.

I'm sorry, I forgot to paste the code. I superseded my first post.
Here is 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";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top