[perl] 続・初めてのPerl 第15章 「Exporter」
練習問題の回答をメモ。
ex15-1(pmファイル)
package Oogaboogoo; use strict; use warnings; use base qw(Exporter); our @EXPORT = qw(number_to_day_name number_to_month_name); my @day = qw(ark dip wap sen pop sep kir); sub number_to_day_name { my $num = shift @_; die "Input number must be between 0 and 6!: $!" if $num < 0 || $num > 6; $day[$num]; } my @month = qw(diz pod bod rod sip wax lin sen kun fiz nap dep); sub number_to_month_name { my $num = shift @_; die "Input number must be between 0 and 11!: $!" if $num < 0 || $num > 11; $month[$num]; } 1;
ex15-2(上のコードに %EXPORT_TAGS を加えただけ。)
our @EXPORT = qw(number_to_day_name number_to_month_name); our %EXPORT_TAGS = ( all => [ @EXPORT ], );
反省点
最後の 1; を忘れないようにしよう。