impossiblerobot has asked for the wisdom of the Perl Monks concerning the following question:
mymodule.plx (test script)package MyModule; use strict; my $inc_dir; LOOP: foreach my $inc (@INC) { opendir(DIR, $inc) or next; while (my $module = readdir(DIR)) { if ($module eq 'MyModule.pm') { $inc_dir = $inc; closedir(DIR); last LOOP; } } closedir(DIR); } print "MyModule found at: $inc_dir\n"; 1;
With this solution, there is a (IMHO small) chance for a race condition. Is there a better way to do this?#!/usr/bin/perl -w # Test MyModule.pm use strict; use MyModule; print "Done.\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Module Self-Location
by japhy (Canon) on Feb 08, 2002 at 16:28 UTC | |
by impossiblerobot (Deacon) on Feb 08, 2002 at 16:54 UTC | |
|
Re: Module Self-Location
by hakkr (Chaplain) on Feb 08, 2002 at 16:28 UTC | |
by japhy (Canon) on Feb 08, 2002 at 16:33 UTC | |
by tye (Sage) on Feb 08, 2002 at 19:25 UTC | |
by japhy (Canon) on Feb 08, 2002 at 19:53 UTC |