Aaron wrote:
>
> I have the following code that I am using to try and get a better
> understanding of how to read from a program and then process the output in
> any way needed:
>
> #!/usr/bin/perl -w
>
> open(IN, 'who | ');
> while(<IN>) {
> $MBody .= $_;
> }
>
> So this section gives me the contents of the who command. Now, what I'm
> trying to do is figure out how to write $MBody into a file. I know that I
> have to open a new file, or can I do it in my prior while?, but am not sure
> on how to get the contents of $MBody into the file. All of my previous
> attempts have left the file empty.
>
> Any help would be appericiated.
While I could try and explain the various forms of open() there is an
excelent tutorial that comes with Perl called perlopentut.
perldoc perlopentut
A shorter way to get the output of an external command into a variable
is to use back-quotes.
my $MBody = `who`;
my $MBody = qx(who); # same thing
perldoc perlop
If you are just going to store the output of an external command into a
file then the system() function might be what you want.
system( 'who > yourfile.txt' );
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]