Martin, James S. wrote:
> while ( ($key1, $value1) = each %hostinfo) {
> print "$key1 has $value1 servers \n";
> print "the servers are\n";
> $n=0;
> until ($n>=$value1) {
>
> foreach (@nbnames) {
> print "$_ $serverinfo{$_}\n";
> $n=$n+1;
> }
>
> }
> }
Your problem here is not with hashes, but rather with your logic - you are
iterating over the entire list @nbnames for each server. Try this:
$n=0;
while ( ($key1, $value1) = each %hostinfo) {
print "$key1 has $value1 servers \n";
print "the servers are\n";
foreach (@nbnames[$n..($n+$value1-1)]) {
print "$_ $serverinfo{$_}\n";
$n=$n+1;
}
}
However, your representation of the data could probably be a little cleaner.
What you have is:
- a list of hostnames
- with each hostname is associated a list of servers (in perl: a hash)
- with each server is associated a logpath (another hash)
The way I'd prefer to do it is like this (note that to get the number of
servers, you only need to look at the size of the array referenced inside
the %servers hash):
%servers = (
'www.blob.com' => [ 'bob1', 'bob2' ],
'www.james.com' => [ 'james1', 'james2', 'james3' ]
);
%serverinfo = (
bob1 => 'blogs1',
bob2 => 'blogs2',
james1 => 'jlogs1',
james2 => 'jlogs2',
james3 => 'jlogs3'
);
while (($key, $value) = each %servers)
{
print "$key has ".scalar(@$value)." servers\nServers are:\n";
foreach (@$value)
{
print "$_ $serverinfo{$_}\n";
}
}
Zoltan.
---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
[EMAIL PROTECTED]
For non-automated Mailing List support, send email to
[EMAIL PROTECTED]