in reply to Piping into system commands
Commands that accept arbitrary input are ones that do some sort of processing on the input, like sorting it, or searching it, or reformatting it. The cp command just copies files; it doesn't do any processing on arbitrary input.
For example, the sort command: you can sort file, to sort the contents of file, or who | sort to pipe the output from who as input to sort. On the other hand, if you do echo 'file' | sort, then you'll just get 'file' back again, rather than the contents of file in sorted order.
So, a good rule of thumb is; if you're telling a command what files to process, you should specify the files as command line arguments. (e.g. system "cp file1 file2";) For arbitrary input, open a pipe. Whenever you're not sure, check the manpage for the command.
BTW, you might prefer to use the File::Copy module for copying files in Perl.
|
|---|