tomazos has asked for the wisdom of the Perl Monks concerning the following question:

One feature of Perl that I use quite often is the ability to parse and concatenate a "glob" of command-line specified files into the standard input.

ie The command-line input is

 ) perl myscript.pl ~/myinput/*

and myscript.pl is:

$/ = "\r"; # I'm on Mac OS X. while (<>) { do stuff with $_ };

..which concatenates all the files in the myinput directory and feeds them to my script one line at a time.

I'm using an environment which doesn't give me access to the command-line (BBEdit, a text editor), and I would like to specify that my input files for use by <> are "~/myinput/*" quickly and easily.

What is the best way to do this from inside the script itself, not using the command line?

Replies are listed 'Best First'.
(ar0n) Re: Moving Input Data Files into Script Proper.
by ar0n (Priest) on Jun 17, 2001 at 17:13 UTC
    You can set @ARGV to whatever you like:
    @ARGV = glob("/home/dir/myinput/*"); while (<>) { # do stuff with $_ }

    ar0n ]

      And if you push:
      push(@ARGV, glob("/home/dir/myinput/*"));
      You get the added bonus of being able to run the script with -d (and other switches) for debugging without having to recode that bit. The filenames just get added onto the end.

        If you are talking Perl's debugger, then changing @ARGV won't have any effect on the -d switch that enables this. @ARGV is the arguments passed to the Perl script and doesn't include (nor modify) the switches and arguments passed to the perl executable (such as -w, -d, or which script to run).

                - tye (but my friends call me "Tye")
Re: Moving Input Data Files into Script Proper.
by Zaxo (Archbishop) on Jun 17, 2001 at 20:45 UTC

    <> uses glob internally. Just say:

    while (<~/myinput/*>) { # do stuff with open(FH,"<".$_ ) };
    This does not cat the files, but reads them one at a time.

    After Compline,
    Zaxo