In my job, I am often in a position where I have to repeat a process on a long list of files, and the process is such that I can only do one file at a time -- e.g. each run produces an output file whose name is derived somehow from the input file name, or whatever.

So one of the first things I did after getting started with perl several years ago was to create a general purpose script that I called "shloop" (as in "shell loop", or more exactly, "sh loop", because it's really just an easier, more flexible tool to use in place of the "for x in ..." loop in (ba)sh). I posted it here.

If there's a process called "mktrace" which only accepts one file name, and I have a long list of file names, I could do:

shloop -e mktrace filename.list
Or if the list were all files in the current directory whose names end in ".fasta" or somesuch, I could do:
ls *.fasta | shloop -e mktrace
On unix, it starts by opening a shell with:
open( SH, "| /bin/sh" ) or die "Couldn't start sub-shell";
Then on each iteration of the loop (as it reads lines from STDIN or a list file), it assembles a "$commandline" by putting the list element together with the value of the "-e" option, and then just does:
print SH $commandline;
The pod provided with the script is pretty extensive (there are a lot more options, like using regex substitutions to create a proper output file spec from the input, putting input and output strings at various points in the command string, etc). If it doesn't suit your needs, it might at least provide some ideas for things to try.

In reply to Re: feeding info to C programs.... by graff
in thread feeding info to C programs.... by bioinformatics

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.