in reply to Real basic...

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; } } }

Replies are listed 'Best First'.
Re^2: Real basic...
by spstansbury (Monk) on Feb 04, 2009 at 16:50 UTC

    Thanks.

    The identifiers are indeed unique, so this should work perfectly. The first section of code works fine, returning the cve_id.

    In the second section the array isn't getting populated

    Any ideas?

      What array? The output is being printed, as it was in your code. If you wish to place the output in an array instead of printing it, place the output in an array instead of printing it.

        Sorry, I meant that after this line of code:

        my ($cve_id, $summary) = @$row;

        These variables appear to be empty, so there is no output.