in reply to Writing unix-style filters

If you don't wanna read from the files on the command line, why are you using <>?

#!/usr/bin/perl # usage: # myscript *.txt # myscript `ls *.txt` # ls *.txt | myscript use strict; use warnings; my @files = @ARGV; if (!-t STDIN) { while (<STDIN>) { chomp; push @files, $_; } } ...

But do you really need this whole STDIN thing?

#!/usr/bin/perl # usage: # myscript *.txt # myscript `ls *.txt` use strict; use warnings; my @files = @ARGV; ...

I must agree on the previously stated point that this is not how unix filters work.

Replies are listed 'Best First'.
Re^2: Writing unix-style filters
by njcodewarrior (Pilgrim) on Apr 11, 2007 at 23:38 UTC

    If you don't wanna read from the files on the command line, why are you using <>?

    Because I'd like to be able to pipe a list of files (from ls, echo, etc) into the script as well as list them on the command line:

    ls *.txt | my_script.pl

    or

    my_script.pl file1.txt file2.txt

    or

    my_script.pl *.txt

    The only way I can figure to do all of the above is using <>.

    I'm learning the ins and outs of the *nix OS at the same time I'm learning perl...am I missing something here?

    njcodewarrior

      Because I'd like to be able to pipe a list of files (from ls, echo, etc) into the script as well as list them on the command line:

      You could easily substitute <STDIN> for <> in your original post since you're using <> exclusively to read from <STDIN>.