Your are using backticks (``) in combination with the system-command. that is plain wrong.
You will have to use
print `command`;
or
system ("command");
Clarification: backticks execute the command and return the output (see perlop). system() will execute the command, while any output of the command will go directly to sdtout.
| [reply] [d/l] [select] |
hm.
The first thing that springs to mind is that you don't need the system call here, you only need the backticks, e.g.,
my $text = `cat $file`;
Do you know about perldoc? It's a great tool. It documents every single function in perl; it's a real lifesaver. Type
perldoc -f system
at a prompt and you'll get all the info you need about system, and how to get the output of a command.
Just a suggestion:
I'd probably do something like the following:
#!/usr/bin/perl -w
use strict;
my $file;
my @files = glob("bin/*.pl");
foreach $file (@files) {
open(FILE, $file) || die "Couldn't open $file: $!\n";
while(<FILE>) {
chomp $_;
print("$_\n");
}
close(FILE);
}
Use perldoc -f to look up each of the glob, open, die, while, chomp, and close functions. | [reply] [d/l] [select] |
You may want to see the following items:
perldoc -f system
perldoc -f exec
perldoc -q command
| [reply] |
First, don't combine system() and backticks, as has been explained.
#!/usr/bin/perl -w
$file = 'index.php';
system("cat $file")
&& die "System call failure: $!\n";
print "\n";
Second, always assume the system call will fail at some time and add an error printout using die or Carp. UN!X System calls use the opposite return result convention to regular perl calls like open(), that's why && rather than the more-usual or.
Update: Also, you can do this without spawning an extra shell by separating the words of the system call:
system('cat', "file") && ..
| [reply] [d/l] [select] |
You can use the qx// operator as well. | [reply] [d/l] |
Besides all the good advices, this print `command`; might confuse you if you have buffered output. Check out $| = 1 to see the command's output straight away and read i.e. Screen Output Buffering. | [reply] [d/l] [select] |