Michael McDonnell wrote:

A popular GNUism might be helpful here as well. Many GNU programs use an option command line argument of "--" to indicate that input should be taken from STDIN instead of from other command line arguments.

'--' is usually used to mean that anything that follows is a non-option argument. For example, to remove a file called '-rf', you could use:


rm -- -rf

to force rm to interpret '-r' as a filename instead of a pair of options.

'-' is usually used as a placeholder for STDIN. Unix programs generally read from STDIN if no files are specified on the command line. If one or more files are specified on the command line, '-' is usually taken to mean STDIN, so

cat foo - bar < baz

would list the contents of foo, then baz, then bar.

But what Eric seems to want to do is supply *data* either from a stream on STDIN or directly on the command line. This is a little unconventional, and you have to remember that the data will have to be parsed differently depending on where it comes from. For example, "foo.pl a b c d e" produces 5 elements in @ARGV, while "echo a b c d e | foo.pl" produces one element (with a newline appended) that has to be parsed and split into elements at the correct places. This can get messy if you have escape characters, whitespace as data, and so on.

I would suggest that the standard way to do this sort of thing would be to read *all* data from STDIN (and, optionally, from files specified on the command line) and treat each line as one record, if your data never contains newlines. If you had some data you wanted to pass manually to the program, you could always invoke it as:

foo.pl
plato-cratylus-1072532262
plato-charmides-1072462708
bacon-new-1072751992
^D

or

echo "plato-cratylus-1072532262
plato-charmides-1072462708
bacon-new-1072751992" | foo.pl

Either that, or supply all data on the command line, and use the backticks method as Michael suggests. Mixing the two conventions might lead to confusion later on, especially if someone else will end up having to use the program.

--
William Wueppelmann
Electronic Systems Specialist
Canadian Institute for Historical Microreproductions (CIHM)
http://www.canadiana.org/



Reply via email to