Created
August 28, 2014 08:49
-
-
Save davorg/2f1a411490e1d4f49082 to your computer and use it in GitHub Desktop.
Simple database query simulated with CSV files and hashes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use 5.010; | |
my %data; | |
open my $fh2, '<', 'file2.txt' or die $!; | |
# Read second file into a hash (for easy access) | |
while (<$fh2>) { | |
chomp; | |
my @row = split /,/; | |
$data{$row[0]} = $row[2]; | |
} | |
open my $fh1, '<', 'file1.txt' or die $!; | |
while (<$fh1>) { | |
chomp; | |
my @row = split /,/; | |
say "$_,", ($data{$row[1]} // 'N.A'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment