in reply to Piping many individual files into a single perl script

I'm at a loss as to how to pipe each of the input files into the program.

program.pl file*

which is the same as

program.pl file1 file2 ...

Then get the names of the files from @ARGV

Update: Oops, not quite the same. On Windows, you'll need to do

use File::Glob qw( bsd_glob ); @ARGV = map bsd_glob($_), @ARGV;

Replies are listed 'Best First'.
Re^2: Piping many individual files into a single perl script
by blazar (Canon) on Sep 29, 2008 at 14:01 UTC

    I personally believe that as a very minor side note, since the OP mentions something like "10000 files," some shells do have problem with a large amount of files. Except that I can't remember how large is large. But I have seen error messages for something like "command line too long" occasionally. In that case, adopting the same technique as for Windows, would be a cure...

    use File::Glob qw( bsd_glob ); @ARGV = map bsd_glob($_), @ARGV;

    This sounds very wrong [Update: but it is right, see my reply to ikegami's comment] unless one has a good reason to do so: since we're on Windows, we most probably want DOS/Windows-like globbing and glob is dwimmy enough to select its own correct "incarnation:" in all of my scripts that may want globbing, written for Windows or "ported" (what a big word!) there from *NIX, I include the same code as BrowserUk's. Sometimes, (depending on how "important" the app will be...) I also provide "standard" -i and -o cli switches for input and output, since shell redirection has some very little but not null deficiencies.

    --
    If you can't understand the incipit, then please check the IPB Campaign.

      I include the same code as BrowserUk's

      But that uses bsd_glob as well. And worse yet, a version that breaks when a space is present.

        Upon reading the documentation for File::Glob I was about to say that I stand corrected, but to be precise, I actually wrote that "This sounds very wrong" (with additional emphasis added now) so I won't, because I still claim that it sounds very wrong. That the actual globbing function's name is bsd_glob() behind the scenes is a matter of fact, but using it explicitly conveys the psychological feeling of resorting to a bsd thingie, whatever it is. The rationale is that perl's glob will dwimmily do whatever is best for the OS one is running under: of course, I acknowledge that there's some sloppiness in this claim since

        • even under *NIX different shells may perform different globbing - I'm not really sure: is there any baseline defined by POSIX?
        • under Windows, it's not defined at all, being left to each individual application: in that case I think that the "standard" behaviour could be defined by that of cli utilities that come with the OS itself...

        Whatever, if e.g. glob() breaks when a space is present, I would still regard it as a feature: provided that does it conform to the standard behaviour on the given OS. Failure to do so would be definitely considered a bug instead.

        --
        If you can't understand the incipit, then please check the IPB Campaign.
      Its not exactly files, its characters :) for example, WinXP its 8191, Win2k/NT4 its 2047