I'd like to get the full filename of an included module. Consider this code:
package MyTest;
my $path = join '/', split /::/, __PACKAGE__;
$path .= ".pm";
print "$INC{$path}\n";
1;
$ perl -Ipath/to/module -MMyTest -e0
path/to/module/MyTest.pm
Will it work on all platforms?
perlvar
The hash
%INC
contains entries for each filename included via thedo
,require
, oruse
operators. The key is the filename you specified (with module names converted to pathnames), and the value is the location of the file found.
Are these keys platform-dependent or not? Should I use File::Spec
or what? At least ActivePerl on win32 uses /
instead of \
.
Update: What about %INC
values? Are they platform-dependent?
Platform dependent typically refers to applications that run under only one operating system in one series of computers (one operating environment); for example, Windows running on x86 hardware or Solaris running on SPARC hardware.
And the language used for developing such applications is called Platform Dependent language. C and C++ are platform-dependent languages.
Explanation: JVM is responsible to converting bytecode to the machine specific code. JVM is also platform dependent and provides core java functions like garbage collection, memory management, security etc. 3.
Platform Dependent means it gets effected by the System Software.It can't be run other systems. Platform Independent means it first converts the program to the intermediate state Byte code (which is platform Independent) and then compiles the program to another language source code.
Given that it's a standard module, go with the approach from Module::Loaded:
sub is_loaded (*) {
my $pm = shift;
my $file = __PACKAGE__->_pm_to_file( $pm ) or return;
return $INC{$file} if exists $INC{$file};
return;
}
sub _pm_to_file {
my $pkg = shift;
my $pm = shift or return;
my $file = join '/', split '::', $pm;
$file .= '.pm';
return $file;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With