If you were forced to look at the files in the order file 1, file 2, you could store the file 1 data in an hash of arrays, with names as keys. Something like this:
#!/usr/bin/perl
use strict;
use warnings;
my $fileNameA = $ARGV[0];
my $fileNameB = $ARGV[1];
my %outputHash = ();
my @line;
my $x = 0;
open (my $inputA, "<", $fileNameA);
while (<$inputA>)
{
next unless $_ =~ m/\w/;
@line = split(" ", $_);
push (@{$outputHash{$line[1]}}, $_);
}
open (my $inputB, "<", $fileNameB);
while (<$inputB>)
{
next unless $_ =~ m/\w/;
@line = split(" ", $_);
if (exists ${$outputHash{$line[2]}}[0])
{
for ($x = 0; $x < @{$outputHash{$line[2]}}; $x += 1)
{
print STDERR "${$outputHash{$line[2]}}[$x]";
}
}
}
But this would only work if the names in file 2 are unique. And it's more efficient to do it the opposite way around if possible, as suggested above.
-Michael
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.