Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are keys and values of %INC platform-dependent or not?

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 the do, require, or useoperators. 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?

like image 892
codeholic Avatar asked Feb 23 '10 14:02

codeholic


People also ask

What is platform dependent example?

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.

Which programming languages are platform dependent?

And the language used for developing such applications is called Platform Dependent language. C and C++ are platform-dependent languages.

Which of the following is platform dependent?

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.

What is platform dependent or independent?

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.


1 Answers

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;
}
like image 171
Greg Bacon Avatar answered Nov 14 '22 09:11

Greg Bacon