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

I have been thinking this to death. Maybe one of you has an answer. I have a tool that extracts data from files of type A and writes it to files of type B. The user supplies file names and a "prefix" value that is used in the generatoin of the B files. The prefix goes inside the file as part of the data. The rules are:
  1. If the input filename has no metacharacters (xxx.A) it is read and processed and the output file is generated. If no output file was specified use xxx.B.
  2. If the input filename has metacharacters, expand it (with glob) to generate a list of input files to process. If no output filename was specified apply the rule in step 1. (So if I have xx1-1.A and xx1-2.A, xx1-?.A processes those and generates xx1-1.B and xx1-2.B). Also, the user may want the output files to be xx1-data-1.B and xx1-data-2.B. I have to assume regular output filenames.
  3. If in either of the above cases an output file is specified, put all the output in that file.
  4. If a prefix was specified, use it to prefix the data in the output file. The trick is that the prefix needs to vary with the input filename, so if I have xx1-1.A and xx1-2.A the user needs to identify that the prefix for the first file is the 1 and the prefix for the second file is the 2.
Yes, this is an algorithm and human factors problem, but I am stuck. Right now I have a GUI with three entry windows: source, destination and prefix. I can handle a single input file and a single output file no problem. I can glob the filenames (this is in Windows) no problem. What I cannot seem to do is figure out how to specify the changing prefix, and how to specify the output file names. And of course, how to code the crazy thing...

I've tried specifying the input as xx1-{?}.A and parsing out the question mark and using it in the output file names, but I couldn't find a good way to generate them. I have the input filenames in an array (@src).

Any ideas about what I should do? --traveler

Replies are listed 'Best First'.
Re: Generating Filenames
by Dogma (Pilgrim) on Nov 27, 2001 at 06:08 UTC
    If I undertand you correctly you want to have multilpe input file names with meta characters that you'll expand using glob dump into the same output file? With your algorithm is it possible to make multiple runs for each glob expansion and then dump the output to the same file or to all these file HAVE to be processed together?
      Dogma, sometimes I'll dump into one file and sometimes I'll process each input file to its own output file. The issues are: generating output file names when I have multiple files and generating prefix information (to identify the input file, really) when it all goes to one file.

      --traveler