[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [Omaha.pm] bad perl - need help - dispatch table



Miller, Scott L wrote:
> Said another way, you expect the files supplied on the command line
> to be processed in order, STDIN is usually on the line before the
> program even:
>
> cat somefile.txt | thisprogram.pl process-this-file.too and-this.one
>
> Therefore, the STDIN stuff comes before the first filename listed...

No. Here is how a typical UNIX "filter" command works: if you put
filenames on the command line, it will read those files (and ignore
stdin); with no filenames, it reads stdin. Some commands (including
cat and perl) further recognize a special "filename" of - which is
just a shorthand for "read stdin". Try it yourself.

# cat a.tmp
this is file a.tmp
# cat b.tmp
this is file b.tmp
# cat c.tmp
this is file c.tmp

# cat a.tmp
this is file a.tmp
# cat <a.tmp
this is file a.tmp
# cat b.tmp <a.tmp
this is file b.tmp

# cat b.tmp | cat a.tmp c.tmp
this is file a.tmp
this is file c.tmp
# cat b.tmp | cat a.tmp - c.tmp
this is file a.tmp
this is file b.tmp
this is file c.tmp
# cat a.tmp - c.tmp <b.tmp
this is file a.tmp
this is file b.tmp
this is file c.tmp

# perl -ne 'print"$ARGV:$_"' a.tmp - c.tmp <b.tmp
a.tmp:this is file a.tmp
-:this is file b.tmp
c.tmp:this is file c.tmp

> is it correct to be able to say
>     thisprogram.pl < somefile.txt ?

Yes. And it is better style (and more efficient) than:

cat somefile.txt | thisprogram.pl

Quoting Tom Christiansen:
  "A wise man once said: if you find yourself calling cat with just
   one argument, then you're probably doing something you shouldn't"
See <http://doc.novsu.ac.ru/oreilly/unix/upt/ch13_02.htm>.

Hugh.



		
_______________________________
Do you Yahoo!?
Win 1 of 4,000 free domain names from Yahoo! Enter now.
http://promotions.yahoo.com/goldrush