I don't have time to address this in depth, but I can at least explain the problem.

In the first pass of the outer loop, the inner loop reads SUMMARY to the end. Thus, in subsequent passes of the outer loop, the inner doesn't get executed since the file pointer is already at the end of the file.

You'll need to seek to the start of the file before the inner loop (poor choice), or load the summary file into memory before entering the outer loop (better choice).

By the way, there's never any reason to do foreach (<$fh>). Use while (<$fh>) instead.

Update: Assuming each line has a unique id,

#!/usr/bin/perl -w use strict; use Text::CSV_XS qw( ); @ARGV == 1 or die("usage: $0 id\n"); my ($query_id) = @ARGV; my $csv = Text::CSV_XS->new(); my $query_cve_id; { my $map_qfn = 'vuln_cve_map.csv'; open(my $map_fh, '<', $map_qfn) or die("Can't open mapping file \"$map_qfn\": $!\n"); while (my $row = $csv->getline($map_fh)) { my ($id, $cve_id) = @$row; if ($id == $query) { $query_cve_id = $cve_id}; last; } } } { my $summary_qfn = 'CVE_summary.csv'; open(my $summary_fh, '<', $sumamry_qfn) or die("Can't open CVE Summary file \"$summary_qfn\": $!\n"); while (my $row = $csv->getline($summary_fh)) { my ($cve_id, $summary) = @$row; if ($cve_id == $query_cve_id) { print("[$cve_id] $summary\n"); last; } } }

In reply to Re: Real basic... by ikegami
in thread Real basic... by spstansbury

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.