in reply to The Grouping of Objects

Create a Team object, which holds references to each Player object that's a member of the team. Arrange for each Player to hold a reference to it's Team.

I assume player lookup by numer is done within the context of a team. You could do it like this:

$player = { grep $_->number() eq $n) $team->players(); print "Player $n is ", $player->name(), "\n" if $player;

Replies are listed 'Best First'.
Re (tilly) 2: The Grouping of Objects
by tilly (Archbishop) on May 06, 2001 at 06:20 UTC
    Your Smalltalk background is showing...

    Perl uses reference counting, not true garbage collection. That means that the above, which creates circular references, will create memory leaks. Therefore you should only have the reference go one way.

    What I would do is have Team be a class, and then have creating a player, and trading players, be methods of the Team object. The Player object would hold the name of the Team, but no direct reference to it.

    I think that does a good job of reflecting your likely usage pattern without creating memory leaks...

    UPDATE
    Alternate answer. With 5.6 use Devel::WeakRef.