http://www.perlmonks.org?node_id=992441


in reply to Merging Two CSV files Based on Two Columns

Please consider adding some code tags in your post, so your data looks more like data.

Note that your first example uses DBD::CSV, which uses Text::CSV_XS underneath to parse the CSV data. Example 2 uses <FINAL> plus invalid split. Examples 3 uses the same reading mechanism as example 2, but with a split that is still unsafe and example 4 uses two endless loops.

If you want to do the "work" yourself and not rely on DBD::CSV, switch to using one of the two proved CSV parsers: Text::CSV (as ig already suggested) or Text::CSV_XS (the fast one).

In what you describe, getline_hr might be very helpful, maybe even getline_hr_all.

use text::CSV_XS; my $csv = Text::CSV_XS->new ({ binary => 1, auto_diag => 1, allow_whit +espace => 1 }); open my $fh, "<", "final2.csv" or die "final2.csv: $!"; $csv->column_names ($csv->getline ($fh)); # Read the header line while (my $r = $csv->getline_hr ($fh)) { $File1Map{$r->{username}} = $r->{date_modified}; } : : $csv->eol ("\n"); # Now use it for output # inside the for/while loop $csv->print ($fh, [ $usename, $oldvalue, $newvalue ]);

Enjoy, Have FUN! H.Merijn