in reply to Problem with data retrieved from Net::SSH:perl
You can use split to split the output into lines:
my ($out, $err1, $exit2) = $ssh->cmd("df -k"); for my $line (split /\n/, $out) { print "$cnt: $line\n"; $cnt++; }
If the output is potentially large (this doesn't apply for df -k but might be useful to know in the future), and you want to avoid copying all the data like split does you might do something like:
or if you're certain the last line ends in a newline, you can simplify the pattern to /\G.*\n/gmy $cnt = 1; while ($out =~ /\G(.+)\n?|\G\n/g) { print "$cnt: $1\n"; $cnt++; }
And finally it might be more efficient to use index and substr, but it would certainly yield more complex code.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Problem with data retrieved from Net::SSH:perl
by runrig (Abbot) on Feb 28, 2003 at 23:37 UTC | |
|
Re: Re: Problem with data retrieved from Net::SSH:perl
by cosmicsoup (Beadle) on Feb 28, 2003 at 20:17 UTC |