[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Get info out a JSON file
Sorry, it was too obvious for me, I didn't realise keys would work on this
kind of hash.
for my $key ( keys %$services ) {
print $services->{$key}->{port};
}
Yeah, I know, I know, I should have just trusted my Learning Perl ;)
h.
On Tue, 1 Dec 2009, Herbie wrote:
> I'm attempting to read someone elses JSON files the structure of which is
> (using Data Dumper):
>
> $VAR1 = {
> 'smtp' => {
> 'up_time' => '*',
> 'checks' => 2,
> 'problem_send_to' => '*',
> 'input' => '',
> 'marginal_send_to' => '*',
> 'port' => 25,
> 'marginal' => '*',
> 'seconds' => 2,
> 'pow' => '*',
> 'critical' => '*',
> 'vital' => 'no',
> 'up_days' => '*'
> },
> 'ssh' => {
> 'up_time' => '*',
> 'checks' => 2,
> 'problem_send_to' => '*',
> 'input' => '',
> 'marginal_send_to' => '*',
> 'hostname' => 'reginald.some.net',
> 'port' => 22,
> 'marginal' => 10,
> 'seconds' => 2,
> 'pow' => '*',
> 'critical' => '*',
> 'vital' => 'no',
> 'up_days' => '*'
> }
> };
>
> All I'm interested in, is the value of the port number for each service, if I
> know the service name in advance I can just do something like
>
> print $services->{ssh}->{port};
> print $services->{smtp}->{port};
>
> which is well and good, but how do I loop through them if I don't know the
> service name (ssh, smtp, whatever) in advance? NB the service name doesn't
> always correspond to what is in /etc/services.
>
> h.
>
> -
> To unsubscribe, send email to majordomo@luci.org with
> "unsubscribe luci-discuss" in the body.
>
-
To unsubscribe, send email to majordomo@luci.org with
"unsubscribe luci-discuss" in the body.