ScooterTrash has asked for the wisdom of the Perl Monks concerning the following question:
How do I parse multi-line output to a system command? For example, I have a list of system names I want to get the IP address using ‘nslookup’. When I use this approach the print statement prints all 5 lines of the nslookup command. It seems no matter how I reference $totalArray I always get all 5 lines of output.
my $totalArray = system ( "nslookup", "$nodeName"); my @totalArraySplit = split(":", $totalArray); print STDOUT ("$totalArraySplit[1]\n");
How do I capture the multi-line output and split it into separate lines I can reference or into a multi-dimensional array?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: capturing and parsing multiline output
by ikegami (Patriarch) on Feb 24, 2009 at 15:52 UTC | |
by ScooterTrash (Novice) on Feb 24, 2009 at 17:14 UTC | |
|
Re: capturing and parsing multiline output
by zentara (Cardinal) on Feb 24, 2009 at 15:59 UTC | |
|
Re: capturing and parsing multiline output
by dwm042 (Priest) on Feb 24, 2009 at 19:49 UTC | |
|
Re: capturing and parsing multiline output
by hbm (Hermit) on Feb 24, 2009 at 16:26 UTC |