So I use 1 PM file and create 3 different objects that an outside script can use and the package xxx; statement seems to work to separate the different objects.package tom; sub new { my $self = "This is tom"; bless ($self, $class); } # (other subroutines for tom go here) package dick; sub new { my $self = "This is dick"; bless ($self, $class); } # (subroutines for dick go here) package harry; sub new { my $self = "This is harry"; bless ($self, $class); } # (routines for harry go here) 1;
My new task:
I need to write a single-file perl script that can be copied to a virgin Linux box and when run, it will scan through lots of stuff to sanity-check the system. Things like users/directories/services/etc.
I want to create a "validate_users" object that I can pass various names and options to and it will validate or explain what is wrong.
Then I want to create a "validate_directory" object that will do similar things for different directories.
But - I want these, and the main code, to all live in a single .pl file to make it easy to pass around and use. (Imagine running this on 800+ different linux box's - each with only standard RedHat linux perl installed).
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.
I am getting the feeling that I am trying to do something "against the rules", but thought I would ask the Monks before giving up and writeing linear code.
What is the correct syntax to create tom/dick/harry objects all in a single .pl file and then use them?
In reply to Can I do single-file, Object oriented perl? by FatDog
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |