You can use reference operator '->' to fetch complex datastructures and the code to display as per your requirement is as follows:%host = ( 'ip1' => { 'tcp' => { '21' => { 'state' => 'open', 'service' => 'ftp' }, '80' => { 'state' => 'open', 'service' => 'web' } } }, 'ip2' => { 'tcp' => { '23' => { 'state' => 'open', 'service' => 'telnet' }, '80' => { 'state' => 'open', 'service' => 'web' } } } );
You can also add 53 open dns to "ip1" as:foreach $ip (keys %host) { print $ip . "\n"; foreach $type (keys %{$host{$ip}}) { foreach $no (keys %{$host{$ip}->{$type}}) { print " " . $no . "\t" . $host{$ip}->{$type}->{$no}->{'sta +te'} . "\t" . $host{$ip}->{$type}->{$no}->{'service'} . "\n"; } } }
Good Luck,$host{'ip1'}->{'tcp'}->{53}->{'state'} = 'open'; $host{'ip1'}->{'tcp'}->{53}->{'service'} = 'dns';
Edited by planetscape - replaced <pre> with <code> tags
In reply to Re: lost in my data structure.
by hraj
in thread lost in my data structure.
by lepetitalbert
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |