我遇到了使用配置文件中定義的常量的問題。 這是我的包:導入require'd文件,就好像它是一個使用語句
package myPackage;
require "APIconfig.pl";
APIconfig::import(APIconfig);
use constant SERVICE_URL => APIconfig::SERVICE_URL();
的配置是這樣的:
package APIconfig;
use constant SERVICE_URL => 'http://api.example.org/blah';
1;
運行此代碼,我得到以下錯誤:
Undefined subroutine &APIconfig::SERVICE_URL called at API.pl line 4.
我不能使用 '使用'而不是'require',因爲這需要將配置文件命名爲.pm,並且在我們網絡上的很多服務器上都將其命名爲.pl。 如何在不重命名文件的情況下使用包?