in reply to format output from a exe within a perl script
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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: format output from a exe within a perl script
by parv (Parson) on Apr 02, 2008 at 03:40 UTC | |
by pc88mxer (Vicar) on Apr 02, 2008 at 07:02 UTC | |
by parv (Parson) on Apr 02, 2008 at 07:48 UTC |