LPM: RE: record creation etc
Rich Bowen
rbowen at rcbowen.com
Tue Feb 6 09:42:46 CST 2001
Fowarding "non-member submission"
-------- Original Message --------
From: "Braun, Thomas " <Thomas.Braun at asbury.edu>
To: lexington-pm-list at happyfunball.pm.org
Subject: RE: record creation in perl
Date: Mon, 5 Feb 2001 22:01:23 -0500
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2653.19)
Content-Type: text/plain
I think something like this is what you're saying:
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
}
For one thing, you will want to include @board as a reference to an
array,
not as an array itself. You could then reference things from @board
with
$by_num{$num}->{BOARD}->[$array_index] for example. It may not be
necessary
to reinitialize $record to {} each time through, but I tend to be
overcautious on stuff like that just to make sure everything gets reset.
Does that help at all?
> -----Original Message-----
> From: owner-lexington-pm-list at pm.org
> [mailto:owner-lexington-pm-list at pm.org]On Behalf Of Kenneth Rogers
> Sent: Monday, February 05, 2001 9:42 PM
> To: lexington-pm-list at happyfunball.pm.org
> Subject: LPM: record creation in perl
>
>
> I've been trying to puzzle this one out of the cookbook for
> about half an hour now and I just can't quite get it.
>
> p.383 if you want to follow along.
>
> They've created a record '$record' which is an anonymous
> hash, they claim to be able to make a hash of these records for use
>
> "#store record
> $byname{ $record->{NAME} } = $record; "
>
> So then in order to make a bunch of these does this mean I
> need to have a $record that's separate for each one that I
> want to build? I'm hoping not I'm trying to make a dynamic
> system where I can create these records (the one's I'm using
> have 4 integers and an array that contains integers and
> characters right now). The problem I see right now is that I
> don't know how to just add a new record to '$byname' without
> completely creating the whole record first, I'd rather be
> able to say something like
>
> $byname{$record->{NUMBER} } = { NUMBER => 2,
>
> PARENT => 1,
>
> BOARD => @board };
>
> but I can't tell if that's legal ( it doesn't compile but
> that could be my fault and not that its impossible to do. )
>
>
> Is there a better way to do this? Maybe a two dimensional
> array or somesuch, I can't figure out how to get the data I
> need packed into a 2D array right now though.
>
> anyway, Thanks In Advance.
>
> Ken R.
>
> OS X: Power meets Grace, Unix with a Macintosh face. -- Salon.com
More information about the Lexington-pm
mailing list