Phoenix.pm: Perl OOP

Mekla mekla at geocities.com
Fri Apr 16 23:18:33 CDT 1999


>LH, which stands for ListHash.  I have often come across situations where
you 
>want data to behave like a list, but yet also have some of the 
>characteristics of a hash.  Its a pretty simple module/object, but it may be 
>a good place to discuss design and scope of an object, something I have 
>probably been bastardizing all along.  If you would like a TXT file of the 
>code, e-mail me. 
>LH allows stuff like:  # 'tis but a sample
>$lh = LH->new('A', 'B', 'C', 'B');
>if ($lh->exists('B'))  # does 'B' exist in this list
>$num_Bs = $lh->num('B');  # $num_Bs is 2
>$lh->insert_after('C', 'CC')  # $lh->list is now 'A', 'B', 'C', 'CC', 'B');
>
>Comment are welcome and appreciated.

I'd like to see the code if you can e-mail it to me at mekla at geocities.com.
Does this just use an array or a hash to create the list. Looks like you
don't keep multiples of any given value in the list but keep a running
total of the value? Is this correct? Can I use insert_after to insert an
array after a given value? For instance if I have a list: (A,B,C,D) could I
insert like such:

$lh->insert_after('C', at array)

??

This would be like a push or a splice. I did something like this for PHP3.
I basically took a whole bunch of Perl functions and ported them to PHP3
and use that library so I have shift, unshift, pop, push, etc as PHP3
functions now :)

I can see a lot of use for a module such as this especially if you want to
keep a running total of a lot of different things and be able to re-access
them easily. With this module you could create trees since they are nothing
more than a bunch of lists really. Just like a list is nothing more than a
bunch of nodes and a forest a bunch of trees, etc.


Shay



More information about the Phoenix-pm mailing list