Hi Monks:

While I have been using Perl for a few years now, I have never quite come upon anything like this. I need to read in a text file containing a list of users (or maybe a comma separated file with users and a kind of access to be granted them) and then append the information to several output text files.

I am looking for the most efficient way to accomplish this. My code which currently just updates one text file is the base of the application.

The following reads in my text file and puts the lines into an array:
# input file open(USERS, $inFile) or die ("Cannot Open $inFile\n"); while($line = <USERS>){ chomp($line); #print $line; #debug print of var push(@userNames, $line); } close(USERS);
and the output file:
open(OUT, ">> $outFile") or die("Cannot Open $outFile\n"); #append to +this file foreach my $USER(@userNames){ print OUT "$USER\n"; } close(OUT);

Note: These are the standard filehandlers in Perl.

Let's say though we want to update 8 different files with the user data (these are a propritory application that has several parts to it, so several 'access files'.

So it would be very nice if someone could point me in the right direction: My thoughts are to make a sub that opens the output file and just call it for however many files need updated in a loop passing the filename to be updated into the sub. But... Is that the most efficient way to do this? Thanks for your help in advance!


In reply to updating multiple text files by jmneedhamco

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.