12.12 組み込み関数をオーバーライドする
標準的な組み込み関数を独自のバージョンに置き換えたい。
- 該当する関数を別のモジュールから自分自身の名前空間にインポートする。
- 関数の定義
package Time::HiRes; use strict; require Exporter; use vars qw(@ISA, @EXPORT_OK); @ISA = qw(Exporter); @EXPORT_OK = qw(time); sub time() {..... } # TBA(未定義)
-
- 関数の呼び出し
use Time::HiRes qw(time); $start = time(); 1 while print time() - $start , "\n";