How would I change this code so it opens all my .txt files one after another (they are numbered sequentially).

In a Bourne-like command shell (like bash), you could do:

for i in *txt; do platon -c $i; done

In Perl on a Unix box (or a shell that expands the command line arguments for you), this should work:

for my $infile (@ARGV){ next unless -e $infile; system("platon -c $infile"); }

This program expects to be passed the whole list of files to process, like this (assuming this code above is in a file called 'batch.pl'):

$ perl batch.pl *.txt

The -e file test operator attempts to make sure that the argument to be processed is an existing file. This is a small attempt to prevent a rogue user from abusing your script. In your environment security may not be an issue, but this sanity check is easy to do.

I don't understand how the $out_filename argument is used in your code, so I've silently ignored it (well, not so silently, I guess :-)

If I were on a Unix system, I'd opt for the small bit of shell script magic to drive your platon program. Of course, I may not be understanding some of your requirements (i.e. do the source files need to be executed in a particular order? Must existing outfiles not be overwritten?, etc). Of course, Perl is great for bring a Unix-like environment to a non-Unix OS. I've done a bit of Perl scripting on NT boxes and Perl has really saved me a lot of MSDOS batch language pain.

Hope this helps.


In reply to Re: opening files by jjohn
in thread opening files by harry34

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.