in reply to Re^2: system command
in thread system command
I want to find the total number of lines without opening the fileThere's simply no way to do that.
If you use wc -l, it opens the file, reads through the content (counting newlines), closes the file and returns a count. Whether you do the reading in Perl, or some external program does, it still must occur.
Also, i am keen to learn how can we use the output of system command (that is directed to STDOUT) within our programUse backticks:
my $file = '/path/to/file'; my $output = `/bin/wc -l '$file'`;
Note $file is subject to shell-escaping rules.
Alternatively, you can use the pipe form of open as ikegami has already observed.
-David
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: system command
by ikegami (Patriarch) on Oct 31, 2007 at 03:39 UTC |