To get you started, have a look at open, readline and close for your file handling. The three-argument form of open using lexical filehandles and testing for success (mention $!, O/S error, on failure) is recommended practice. E.g.

my $inputFile = q{xyz.txt}; open my $inputFH, q{<}, $inputFile or die qq{open: < $inputFile: $!\n}; my $outputFile = q{abc.txt}; open my $outputFH, q{>}, $outputFile or die qq{open: > $outputFile: $!\n};

Read your files in a while loop line by line, either into the default pattern space, $_ (see perlvar) or a lexical scalar. Consider whether to remove line terminators using chomp. E.g.

# Reading lines into $_ in a while loop and removing # line terminator while( <$inputFH> ) { chomp; # Acts on $_ by default ... # Rest of your line-processing code here }

Extracting the data fields could be done using regular expressions, have a look at perlretut and perlre. Consider using global matching in File 2 to extract a series of name data into an array. This pattern (not tested) looks like it will match data for one name, the whole data including the name captured in $1, the name alone in $2

my $rxExtractNameData = qr {(?x) ( \s+ (\w+) \s+ \([A-Z]\) \s+ \(\d*%\) \s+ \d+\s+\+\s+[+-]?\d+ ) };

Have a crack at putting some of these ideas together. Build your script gradually, first just getting it to open and close File 1 and, when that works, read the lines and extract the names (and numbers if necessary, do the numbers in File 1 have to match those in File 2?). If you encounter difficulties come back to the Monastery with more questions.

I hope these thoughts are helpful

Cheers,

JohnGG


In reply to Re: File Intersection problem by johngg
in thread File Intersection problem by ashnator

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.