Esteemed Monks,

Let me first try to describe the problem I am trying to solve:

I have a large file with many complex entries, each relating to a file in a Unix filestore tree.

I wish to extract a subset of these entries to match part of the current filestore tree; I can produce a list of the current filestore tree using the 'find' command.

So I have two files:

The true filestore list

/fred/myfile
/fred/myfile2
/bert/myfile

The large complex file

user ALLFILES /fred/myfile=/archive/dingbat/fred/myfile 3 6 9 thegoosedrankwine
user ALLFILES /fred/myfile2=/archive/dingbat/fred/myfile 3 6 9 thegoosedrankwine
user ALLFILES /fred/myfile3=/archive/dingbat/fred/myfile 3 6 9 thegoosedrankwine
user ALLFILES /bert/myfile=/archive/dingbat/fred/myfile 3 6 9 thegoosedrankwine
user ALLFILES /bert/myfile2=/archive/dingbat/fred/myfile 3 6 9 thegoosedrankwine

You will note that the third field (up to the '=') in the complex file is the filename in the real filestore tree.

My tentative plan is to set up the first file as a hash, indexed by the whole contents of each line, and then read serially through the second file, splitting out the file name component and matching it with the Hash.

If I get a hit, I then overwrite the matching entry in the Hash with the current line in my complex input file.

At the end I should have copied all the matching entries out of the complex file, and these should now be in the other file.

Any lines without a match will be unchanged.

So, the question:

Can I use 'Tie::File' to generate the Hash (which makes this scalable to work with large files and small memory), should I work in memory, or is there some other Perl feature which will make this so easy that I will be embarrased that I asked the question.

TIA

LGC

Nothing succeeds like a budgie with no teeth.

In reply to Tie::File to create a Hash? by LittleGreyCat

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.