in reply to Tracking objects.

That would be one way, but you need to change:
my $x = Test->new(); my $dog = \$x; push @pack, $dog;
to just:
push @pack, Test->new();

Replies are listed 'Best First'.
Re^2: Tracking objects.
by saberworks (Curate) on Nov 26, 2004 at 10:23 UTC
    The reason this is suggested is because the new() returns a blessed reference, then you are creating a reference to said blessed reference, and then you are pushing that reference-to-a-reference onto your array. It's better to just push the blessed reference itself.
Re^2: Tracking objects.
by BUU (Prior) on Nov 26, 2004 at 10:10 UTC
    And since we're nitpicking, your (the original poster's) use of @pack as a global variable is bad form:
    #!/usr/bin/perl use Dog; my @pack = create_dogs(15); sub create_dogs #of course, this should possibly be a method of Dog, b +ut whatever { my $num = shift; map Dog->new, 1 .. $num; # or 0, whichever makes you happy. }