曜日(月)名から数字の変換
back
数字から曜日(月)名への変換はリストを使えば簡単
$month = "0から11の何か";
$month_name = ("Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec")[$month_day];
逆変換は、ハッシュのリファレンスを使うとラク
$month = {Jan => 1, Feb => 2, Mar => 3, Apr => 4, May => 5, Jun => 6,
Jul => 7, Aug => 8, Sep => 9, Oct => 10, Nov => 11, Dec => 12}->{$month_name};
あるいは、事前にハッシュを用意しておく
%month_name = (Jan => 1, Feb => 2, Mar => 3, Apr => 4, May => 5, Jun => 6,
Jul => 7, Aug => 8, Sep => 9, Oct => 10, Nov => 11, Dec => 12);
$month = $month_name{$num};
back