OOP

Ed L. pppm at bluepolka.net
Mon Sep 30 18:48:53 CDT 2002


On Monday 30 September 2002 04:41 pm, John Evans wrote:
> I'm doing pretty good at OO Perl, but I would like to know if there is a
> way to create an package, OOP it, and use it all in a single file. I'm
> trying to write a small script that would be very easy to OOP, but I
> don't want to have to manage two seperate files (just in case they get
> serparated and the whole thing falls apart.)

How about this one?


oop.pm:
package oop;
sub new {
}
print "Do something.\n";



You could check $0 to see if it was called standalone or included as a 
module.  Or check the call stack.

Ed



>
>
> At the moment, I have been doing something like:
>
> FILE: Lookup.pm
> =============
> package Lookup;
>
> sub new {
> # blah blah blah
> }
>
> sub find_user {
> # blah blah blah
> }
>
>
> FILE: finduser.pl
> ====================
> use Lookup;
>
> $users{"Joe"} = Lookup->new(183);
> $users{"Bob"} = Lookup->new(184);
>
> foreach $user (sort keys $users) {
>   $users{$user}->find_user();
> }
>
>
> Basically, I'm trying to combine Lookup.pm into finduser.pl so that I
> just have a single file.
>
> What's the trick to get it done?
>
> Thanks!



More information about the Pikes-peak-pm mailing list