in reply to Re^2: Parsing output from Nmap::Scanner with varying hash address.
in thread Parsing output from Nmap::Scanner with varying hash address.

I do not know if this is cleaner or more elegant, but you could remove most of these -> dereferencing arrows (those between closing and opening curly braces), thereby making the syntax at least a bit shorter.

Something like this should probably work (but is untested):

my %shortlist; for my $key (keys $results->{'ALLHOSTS'}){ for my $key2 (keys $results->{'ALLHOSTS'}{$key}{'ports'}{'tcp'}){ $shortlist{"$results->{'ALLHOSTS'}{$key}{'ports'}{'tcp'}{$key2 +}{'service'}{'name'}"} = $results->{'ALLHOSTS'}{$key}{'ports'}{'tcp'} +{$key2}{'state'}; } }

Replies are listed 'Best First'.
Re^4: Parsing output from Nmap::Scanner with varying hash address.
by kcott (Archbishop) on Jul 11, 2015 at 22:15 UTC

    Removing most of the '->'s is a good idea. You could also remove 26 single-quotes (around all the literal key names) and a pair of double-quotes. Splitting the assignment over two lines gives a maximum line length of 80 characters (previously 156). I think that provides additional readability.

    my %shortlist; for my $key (keys $results->{ALLHOSTS}) { for my $key2 (keys $results->{ALLHOSTS}{$key}{ports}{tcp}) { $shortlist{$results->{ALLHOSTS}{$key}{ports}{tcp}{$key2}{servi +ce}{name}} = $results->{ALLHOSTS}{$key}{ports}{tcp}{$key2}{state}; } }

    [Note: as I'm editing untested code, mine is also untested.]

    Update: I've also added spaces before the opening braces of the for blocks: I think that makes those a little clearer.

    -- Ken

      Yeah, right, Ken, I did not think about it, but yes, removing the useless quote marks is also making the syntax much shorter (and cleaner in my view). ++.