in reply to Question about data structures
It looks as if you're trying to make an array of hashes.
@services = ( { serviceid => '1', name => 'servicea', host => [ qw( hosta hostb ) ] }, { serviceid => '2', name => 'serviceb', host => [ qw( hostc ) ] }, );
With this, you can loop through your services like so:
foreach my $svc ( @services ) { # list of hosts: @{ $svc->{host} } # name: $svc->{name} }
If you want, you can make a hash keyed on one of those fields instead. For example, keyed on the service name:
%services = ( 'servicea' => { serviceid => '1', host => [ qw( hosta hostb ) ] }, 'serviceb' => { serviceid => '2', host => [ qw( hostc ) ] }, );
With this, you can address a particular service by name and get the field you want. Examples: @{ $services{'servicea'}->{host} } and $services{'servicea'}->{serviceid}.
Hope this helps.
|
|---|