in reply to Can I do single-file, Object oriented perl?
What is the correct syntax to create tom/dick/harry objects all in a single .pl file and then use them?
Being Perl there is no "correct" way - TIMTOWTDI and all that :-) That said I tend to always write inline classes like this:
{ package Foo; sub new { bless {}, shift } # ... other methods } { package Bar; use base 'Foo'; # Bar specific methods }
Sticking each package in its own { block } means I don't have to worry about lexical variables leaking between packages, and using use base rather than assigning to @ISA directly means I don't have to add extra use BaseClass lines if I decide to move it to a separate file.
|
|---|