[plug] [OT] Perl Array/List/Hash Question
hooker at iinet.net.au
hooker at iinet.net.au
Wed Feb 9 06:12:15 WST 2005
Quoting Timothy White <weirdo at tigris.org>:
> Basically I am attempting to implement a mini database in perl.
> It goes like this, read in file in colon delimited format.
> Use split to split it into components
> Using the username component create a new 'database' entry with user data.
> modify database.
> write database back out.
>
> The bit I am having problems with is storing the database.
> I have tried
> $database{$username}->{'passwd'} = 'random';
> and that appears to work except I can't write it out again.
> foreach $user ($database){}
> doesn't return anything.
>
> I basically need to iterate through the database recovering all values
> as well as the changes.
Tim, although $database is a hash, each element is actually a hash reference
rather than a hash, so :
foreach my $Key1 (sort keys %database) {
foreach my $Key2 (sort keys %($database{$Key1}}) {
print $database{$Key1}->{$Key2},"\n";
}
}
.. and so on.
Hope this helps.
Hook
More information about the plug
mailing list