Skip to content

Instantly share code, notes, and snippets.

@note103
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save note103/bc7640bae1ddb4202202 to your computer and use it in GitHub Desktop.
Save note103/bc7640bae1ddb4202202 to your computer and use it in GitHub Desktop.
日付を入れて曜日を出すPerlスクリプト
#!/usr/bin/env perl
use strict;
use warnings;
print "Input a date with 'YYYYMMDD' or 'YYYY/MM/DD' or 'YYYY-MM-DD'.\n";
my $day = [qw(
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
)];
my $daydate = {
#ここに日付&曜日を入れる
20140526 => "$day->[2]",
20140527 => "$day->[3]",
20140528 => "$day->[4]",
20140529 => "$day->[5]",
20140530 => "$day->[6]",
20140531 => "$day->[0]",
20140601 => "$day->[1]",
20140602 => "$day->[2]",
20140603 => "$day->[3]",
20140604 => "$day->[4]",
20140605 => "$day->[5]",
};
my $quit = 'q|d|\n';
while (my $in = <>) {
if ($in =~ /^(q|d)$/) {
print "Bye!\n";
last;
} elsif ($in =~ /^((\d{4})[\/-]?(\d{2})[\/-]?(\d{2}))$/) {
my $indate = $1;
my $key = "$2$3$4";
print "$daydate->{$key}\n\nIf you continue, input a date. If not, press 'q'.\n";
} else {
print "\nPlease input a correct date.\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment