LPM: RE: record creation etc
Steve Lane
sml at zfx.com
Tue Feb 6 12:35:53 CST 2001
> From: "Braun, Thomas " <Thomas.Braun at asbury.edu>
>
> my (%by_num, $not_done, $record, $number, $parent, @board);
> $not_done = 1;
> while ($not_done) {
> $record = {};
> # Get your $number, $parent, and @board however you like
> $record->{PARENT} = $parent;
> $record->{BOARD} = \@board;
> $by_num{$number} = $record;
> # Figure out if you're done and set your test condition accordingly
> }
one major problem here: $record->{BOARD} will have the same value
(the last value of @board) for all entries, because it's lexicalized
outside the loop, and so the $record->{BOARD} references all point
to the same value.
to fix, either use:
$record->{BOARD} = [ @board ];
or
while ($not_done) {
my @board; # i.e. lexicalized inside the loop
--
Steve Lane <sml at zfx.com>
More information about the Lexington-pm
mailing list