[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[coldsync-hackers] New Perl question; Do I need to keep both a hash and an array?
- To: coldsync-hackers at lusars dot net
- Subject: [coldsync-hackers] New Perl question; Do I need to keep both a hash and an array?
- From: Izzy Blacklock <izzyb at ecn dot ab.ca>
- Date: Sat, 07 Jun 2003 13:32:37 -0600
- Reply-to: coldsync-hackers at lusars dot net
- Sender: owner-coldsync-hackers at lusars dot net
- User-agent: KMail/1.5
First off, I discovered my bug of using @_ not $_ in my previous post. Oops!
Other then that, it seems to work like a charm. ;)
Here's another area in my code that's been bugging me though.
# XXX This is where I parse the TitraxNamesDB data for further use
# Below. It'd be nice not to need to keep both an array and a hash,
# but I can't think of how at the moment. The hash makes most sense
# for extracting data from Datebook, but an array is needed to
# match the project name with the notes out of the TitraxNoteDB.
my %NamesHash;
my @NamesArray;
my $record;
my $i=0;
foreach $record (@{$pdbs{TitraxNameDB}->{records}})
{
my $text = $record->{data};
$text =~ s/\\/\\\\/g;
$NamesHash{$text} = 1;
$NamesArray[$i] = $text;
$i++;
}
Is there a way around needing to populate both an array and a hash? Here's
how each is being used:
foreach $record (@{$pbds{DatabookDB}->{records}})
{
next unless $NamesHash{ $record->{"description"} };
.... Do stuff ...
}
and
$i=0;
foreach $record (@{$pdbs{TitraxNoteDB}->{records}})
{
$description = $NamesArray[$i];
..... Do more stuff ....
$i++;
}
Is there a way to do this without using both an array and a hash?
...Izzy
--
This message was sent through the coldsync-hackers mailing list. To remove
yourself from this mailing list, send a message to majordomo@thedotin.net
with the words "unsubscribe coldsync-hackers" in the message body. For more
information on Coldsync, send mail to coldsync-hackers-owner@thedotin.net.