How about something like this:
open F,"somecmd |" or die "error spawning command $!";
my $data='';
while(<F>){
$data.=$_;
print;
}
close F;
| [reply] [d/l] |
Thanks that worked great. I did see something like this
before but the explaination of what it does did not match
what I was looking for. Once again thank you.
| [reply] |
I'd suggest using open. Breifly, it would work something like this:
#!/usr/bin/perl -w
use strict;
my($program) = 'cat';
my(@ary);
open(CAT,"$program ~/foo.txt |") || die "Unable to run $program: $!\n"
+;
foreach (<CAT>) {
push @ary, $_;
print "$_";
}
close(CAT);
Of course, TIMTOWTDI, with backticks, for example. However, this method has worked well for me in the past.
Note: Taint checking is left as an exercise for the reader.
Hope that helps,
Shendal | [reply] [d/l] |
Both lhoward's and Shendal's answers are good examples of
what I think is a more general Way To Think About The
Problem: If you can capture the data into a variable,
just print the variable, and then the results
are on the screen as well.
Another example (backticks, as Shendal mentioned):
my $answer = `/usr/local/bin/arbitrary_script_that_prints_something`;
print $answer;
If you're writing short scripts or one-liners, you might
man perlrun and check out the -e, -n, and -p
options. In short scripts these can remove 90% of the
skeleton code for you.
Alan | [reply] [d/l] [select] |