Skip to content

Instantly share code, notes, and snippets.

@davorg
Created August 28, 2014 08:49
Show Gist options
  • Save davorg/2f1a411490e1d4f49082 to your computer and use it in GitHub Desktop.
Save davorg/2f1a411490e1d4f49082 to your computer and use it in GitHub Desktop.
Simple database query simulated with CSV files and hashes
#!/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