On 04/27/00, ""Martin, James S." <[EMAIL PROTECTED]>" wrote:
> Ok, I've spent 4 + hours trying to figure this one out, in addition to
> digging through the perlfaq and the O'reilly Perl books... I have two
> hashes that are made from 4 arrays.... it's easier if I show you the code:
>
>
> @nbnames = qw (bob1 bob2 james1 janes2 james3);
> @logpaths =qw (blogs1 blogs2 jlogs1 jlogs2 jlogs3);
> @hostsnames=qw(www.bob.com www.james.com);
> @number_of_servers=qw(2 3);
(foreach hash assignment stuff clipped)
The assignments can be done alot easier if indeed
you have the above arrays to start with:
my (%serverinfo, %hostinfo);
@serverinfo{@nbnames} = @logpaths;
@hostinfo{@hostsnames} = @number_of_servers;
But that doesn't help much, how do you tie www.bob.com to
bob1 or www.james.com to james2? It seems like you need
some other kind of data structure, so how about this:
my %srvrinfo;
while ( my ($nbserver, $logpath) = each %serverinfo) {
# Get the 'base' servername
(my $servername = $nbserver) =~ s/\d+$//;
$srvrinfo{$servername}{$nbserver} = $logpath;
}
my %sysinfo;
while ( my ($hostname, $nbr_srvrs) = each %hostinfo) {
# Get 'base' servername (I'm just assuming its
# the part between the 'www.' and the '.com' - YMMV
my ($servername) = $hostname =~ /www\.(.*?)\.com/;
$sysinfo{$servername}{HOSTNAME} = $hostname;
$sysinfo{$servername}{NUM_SRVRS} = $nbr_srvrs;
$sysinfo{$servername}{NB_INFO} = $srvrinfo{$servername};
}
# Now to iterate through this
while (my ($servername, $serverinfo) = each %sysinfo) {
print "$serverinfo->{HOSTNAME} has $serverinfo->{NUM_SRVRS} servers\n";
my $nb_info = $serverinfo->{NB_INFO};
for my $nbname (sort keys %$nb_info) {
print "$nbname logfile is $nb_info->{$nbname}\n";
}
}
All completetly untested,
HTH,
Douglas Wilson
---
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]