This program needs to be automated to the point of taking a given folder (stated by user), and assigning a filehandle to each text file. Once this is done, I need to be able to reference each so my basic parsing element can act on each file and converge the data into one output file.

If I read that right, you want to have all of the filehandles at the same time, presumably so you can read from each as you need to rather than process the files sequentially. This mostly untested code:

sub get_filehandles { my $dir = shift; opendir my ($dh), $dir; my @fhs = map { my $fh; open( $fh, '<', "$dir/$_" ) ? $fh : do { warn "$dir/$_: $!"; () } } grep { -f "$dir/$_" } readdir($dh); closedir $dh; return \@fhs; }
will return a reference to an array of filehandles open for reading. (You must pass in the path to the directory where the files are.) Keep in mind that you may have limits on the number of filehandles you can have open at once.

Update: Fixed a bug. I was always returning the filehandle whether it was successfully opened or not. It shouldn't barf with warnings on now. I also tried to improve its readability a bit.

-sauoq
"My two cents aren't worth a dime.";

In reply to Re: Variable numbers of folders... by sauoq
in thread Variable numbers of folders... 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.