<?xml version="1.0" encoding="windows-1252"?>
<node id="994424" title="Re^5: Merging Two CSV files Based on Two Columns" created="2012-09-19 03:58:37" updated="2012-09-19 03:58:37">
<type id="11">
note</type>
<author id="200365">
Tux</author>
<data>
<field name="doctext">
&lt;p&gt;That last loop obviously is wrong. You cannot loop over a file handle. Certainly not over one that has been read to the end. Compare to below example and work out what you want exactly yourself&lt;/p&gt;
&lt;code&gt;
open my $fh1, "&lt;", "final.csv" or die "final.csv: $!";
$csv-&gt;column_names ($csv-&gt;getline ($fh1)); # Read the header line
while (my $row = $csv-&gt;getline_hr ($fh1)) {
    $File1Map{$row-&gt;{username}} = $row-&gt;{date_modified}; # NO "my" there!
    }

open my $fh2, "&lt;", "HCDir.csv" or die "HCDir.csv: $!";
$csv-&gt;column_names ($csv-&gt;getline ($fh2)); # Read the header line
while (my $row = $csv-&gt;getline_hr ($fh2)){
    $File2Map{$row-&gt;{fullname}} = $row-&gt;{branch}; # NO "my" there!
    }
    
$csv-&gt;eol ("\n"); # Now use it for output
open my $fh3, "&gt;", "completed.csv" or die "completed.csv: $!";
$csv-&gt;print ($fh3, [qw( user date_modified branch )]);
foreach my $user (sort keys %File1Map) {
    $csv-&gt;print ($fh3, [ $user, $File1Map{$user}, $File2Map{$user} || "?" ]);
    }
close $fh3;
&lt;/code&gt;
&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-200365"&gt;
&lt;br /&gt;
Enjoy, Have FUN! H.Merijn
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
992384</field>
<field name="parent_node">
994342</field>
</data>
</node>
