営業日計算


```
$ cpanm Calendar
$ cpanm Calendar::Japanese::Holiday
$ cat sample.pl
use strict ;
use warnings ;
use Calendar ;
use Calendar::Japanese::Holiday;

sub get_limit_date {
    my $date  = Calendar->new_from_Gregorian( @{ shift @_ } );
    my $limit = shift || 5 ;
    # 土日、祝日外公休日
    my %day_off = (
        '08/14/2015' => 1,
        '12/30/2015' => 1,
        '12/31/2015' => 1,
    ) ;
    my $i = 0 ;
    LOOP:
    while ( 1  ){
        $date ++ ;
        # 土日は除外
        next LOOP if $date->weekday % 6  == 0 ;
        # 祝日は除外
        # 最後の 1 は振替フラグ（ON）
        next LOOP if isHoliday( $date->year, $date->month, $date->day, 1);        
        # それ以外のお休みの日だったら
        next LOOP if defined $day_off{ $date } ;        
        # カウンターがリミット未満なら
        next LOOP if ++ $i  < $limit ;
        last LOOP ;
    }
    return $date->date_string("%Y/%m/%d") ;
}

printf "%s\n",  get_limit_date  [ qw( 6 22 2015 )] ; #1
$ perl ./sample.pl
```


* 当日を一日目と勘定するか否かは、ケースバイケースで調整
* `YYYYMMDD` ではなく、`MMDDYYYY` で入力。出力で調整
* `%day_off` の中身とかは外部ファイルなどにする


## 20150908 | 追記
ひょんな事から、使おうと思って、コードに埋め込んだら、

```
Use of each() on hash after insertion without resetting hash iterator results in undefined behavior at ${PLENV_ROOT}/versions/5.18.4/lib/perl5/site_perl/5.18.4/Calendar/Japanese/Holiday.pm line 332
```
なんぞのエラーが。

自分のコードが原因かと思って、探し回ったが、当然そんな事は無い。
指定日付によって偶発的に発生する模様。
勘弁してよ、、、


### （私の環境下での）再現方法

最後の行（#1）を以下に変更して、

```
for my $i ( 1 .. 30 ) {
    print $i . qq{\t} ;
    printf "%s\n",  get_limit_date  [ 9, $i, qw( 2015 )] ;
}
```

```
$ perl ./sample.pl
Use of each() on hash after insertion without resetting hash iterator results in undefined behavior at  ${PLENV_ROOT}/versions/5.18.4/lib/perl5/site_perl/5.18.4/Calendar/Japanese/Holiday.pm line 332.
1       2015/09/08
2       2015/09/09
3       2015/09/10
4       2015/09/11
5       2015/09/11
6       2015/09/11
7       2015/09/14
8       2015/09/15
9       2015/09/16
10      2015/09/17
11      2015/09/18
12      2015/09/18
13      2015/09/18
14      2015/09/24
15      2015/09/25
16      2015/09/28
17      2015/09/29
18      2015/09/30
19      2015/09/30
20      2015/09/30
21      2015/09/30
22      2015/09/30
23      2015/09/30
24      2015/10/01
Use of each() on hash after insertion without resetting hash iterator results in undefined behavior at  ${PLENV_ROOT}/versions/5.18.4/lib/perl5/site_perl/5.18.4/Calendar/Japanese/Holiday.pm line 332.
25      2015/10/02
Use of each() on hash after insertion without resetting hash iterator results in undefined behavior at  ${PLENV_ROOT}/versions/5.18.4/lib/perl5/site_perl/5.18.4/Calendar/Japanese/Holiday.pm line 332.
26      2015/10/02
Use of each() on hash after insertion without resetting hash iterator results in undefined behavior at  ${PLENV_ROOT}/versions/5.18.4/lib/perl5/site_perl/5.18.4/Calendar/Japanese/Holiday.pm line 332.
27      2015/10/02
Use of each() on hash after insertion without resetting hash iterator results in undefined behavior at  ${PLENV_ROOT}/versions/5.18.4/lib/perl5/site_perl/5.18.4/Calendar/Japanese/Holiday.pm line 332.
28      2015/10/05
Use of each() on hash after insertion without resetting hash iterator results in undefined behavior at  ${PLENV_ROOT}/versions/5.18.4/lib/perl5/site_perl/5.18.4/Calendar/Japanese/Holiday.pm line 332.
29      2015/10/06
30      2015/10/07
```

plenv が入ってない mac でも再現

### コード変更。

まあ、自分でコードを書くのもかったるいし、エラーの内容見れば、明白で、 `Calendar::Japanese::Holiday` を直接弄って


```
$ diff Holiday.pm.bak Holiday.pm
332c332,334
<       while (my ($day, $name) = each %holidays) {
---
>       #while (my ($day, $name) = each %holidays) {
>     for my $day ( keys %holidays ){
>         my $name = $holidays{$day} ;
```

して使う事に。