Ryan Dillinger wrote:
Hello,
>
I have a script here, that when I run it, it gives me this: Can't return
outside a
subroutine at tire.pl line 14. Can someone help me figure out what I'm
doing wrong?
Thank You very much for your help!
#!/usr/bin/perl
# tire.pl
use warnings;
package CreateTire;
sub new {
my $tire = {};
bless $tire;
return $tire;
}
sub tread{ my $tiretread = 'wavy'; };
sub hubcap{ my $hubcap = 'metal'; };
sub psi{ my $tirepsi = '40 pounds per square inch'; };
return 1;
Hi Ryan
It's looks like you're writing a perl module, which needs to evaluate to true
when it's 'require'd. Using return() like this is, as the compiler says, illegal
outside a subroutine. Just remove the 'return' and leave just the 1; on its own
on the line.
Also, 'use strict' as well as 'use warnings'.
There's a lot left to do before you have a working object, but I'll wait till
you get a little further.
Cheers,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>