#navi_header|Perl| - @INCをスクリプトで調整し、任意のディレクトリの.pmファイルをuseできるようにしてみる。 - <= Perl 5.8 - ./manip_inc01.pl #!/usr/bin/perl use strict; use warnings; use File::Basename; # adjustment for include path (terminate with path separator) BEGIN { my (undef, $__base_dir, undef) = fileparse($0); # File::Basename push(@INC, $__base_dir); } use test::Test1; print $test::Test1::msg, "\n"; - ./test/Test1.pm package test::Test1; use strict; use warnings; our $msg = "Hello, test::Test1!"; - 出力 $ perl ./manip_inc01.pl Hello, test::Test1! - ポイント:File::Basename::fileparseで取得できる、スクリプトファイル自身($0)のディレクトリを、BEGINブロックで@INCにpushしている。 - PHPの擬似コードだと次の様になる。