holiday/merge

42 lines
1.1 KiB
Perl
Executable File

#!/usr/bin/perl
use strict;
use warnings;
my $meanings_file = 'meanings-jp.csv';
open my $fh_meanings, '<', $meanings_file
or die "Cannot open $meanings_file for reading: $!";
my $holidays_file = 'holidays-jp.csv';
open my $fh_holidays, '<', $holidays_file
or die "Cannot open $holidays_file for reading: $!";
my $output_file = 'merged-jp.csv';
open my $fh_out, '>', $output_file
or die "Cannot open $output_file for writing: $!";
my @meanings;
while ( my $line = <$fh_meanings> ) {
chomp $line;
my @fields = split /,/, $line;
push @meanings, \@fields;
}
while ( my $line = <$fh_holidays> ) {
chomp $line;
my @fields = split /,/, $line;
my $date_raw = $fields[0];
$date_raw =~ m|(\d+)/(\d+)/(\d+)|;
my $date = sprintf( "%04d-%02d-%02d", $1, $2, $3 );
my $name = $fields[1];
my $rule = "振替休日";
my $meaning = "祝日法による休日。";
for my $row (@meanings) {
if ( $$row[0] eq $name ) {
$rule = $$row[1];
$meaning = $$row[2];
last;
}
}
print $fh_out "$date,$name,$rule,$meaning\n";
}