in reply to Can I do single-file, Object oriented perl?
I have tried creating a .pl file and the keyword "package" throws errors. I have tried creating a .pm file, then putting main code (even "print 'Hello World', before the "1;", and this throws different errors.
That makes no sense. If it works in the .pm, it'll work in the .pl. Another error must have been introduced. (It sounds like a runaway quote or a runaway block to me.)
package AverageJoe; sub get_name { ${shift(@_)} } package tom; our @ISA = 'AverageJoe'; sub new { my $class = shift; my $text = "This is tom"; return bless(\$text, $class); } package dick; our @ISA = 'AverageJoe'; sub new { my $class = shift; my $text = "This is dick"; return bless(\$text, $class); } package main; # Not mod_perl safe. my $tom = tom->new(); my $dick = dick->new(); { print $tom->get_name(), $/; print $dick->get_name(), $/; }
I had to make changes since 1) you weren't blessing a reference, and 2) you used $class without declaring or initializing it.
|
|---|