Hello, I'm a newbie to Perl lanaguage and have only basic programming knowledge.

I want to know if this possible solution to the following problem might work:

First, I have a list of account numbers in a file called accts.txt that contains 10 different account numbers (1 per line)

Secondly, I have my data files in another directory, in which I want to retrieve information for the set of account numbers in accts.txt

What I am trying to do here is to create a smaller subset of my data for only the account numbers I want to pull data for from each of the files.

At first, I wrote a short script to grep each line for all files in the directory for an accountthat exists in accts.txt

But the challenge here is that the account numbers maybe listed in multiple places in a single line. I only want to search in the account number field. However, the account number field maybe the second field in one file, and the 5th field in another file. (The data is .txt files with | as the delimiter)

For example, I have a set of 10 files. For 7 out of 10 files, the account number is the first 9 characters in the line (also known as the first field). I am using substr function to check if the account number from accts.txt matches the first 9 digits in each line of each of these 7 files. But I am not sure how to handle this for the other 3 files, where acct number is located in digits 21-29, 11-19, and 12-20 subsequently.

I would use a foreach loop to read through the files, but can I use if conditions within foreach to exclude the other 3 files?

Any suggestions would be greatly appreciated! Thanks!

In reply to retrieving information from a set of files by Anonymous Monk

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.