The only significant thing I would change is to use if/elsif/elsif/... to check for the various key/value pairs:for(@PORTS){ ($KEY,$VAL)=split(/:/); $HOST=$VAL if $KEY =~ /Host/; $CONNTIME=$VAL if $KEY =~ /Connection time/; $CONNEDHOST=$VAL if $KEY =~ /Connected host/; ...
It's safer and more efficient.if ($KEY =~ /Host/) { $HOST = $VAL; } elsif ($KEY =~ /Connection time/) { $CONNTIME = $VAL; } elsif ($KEY =~ /Connected host/) { ... } ...
Update: Note that you don't have to explicitly "delete the first three lines" of the output because none of the patterns you are matching against occur in the first three lines. However, if you want to be sure that the first three lines won't enter the for loop, you can eliminate them with:
splice(@PORTS, 0, 3);
In reply to Re: format output from a exe within a perl script
by pc88mxer
in thread format output from a exe within a perl script
by swartzieee
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |