So I want to find the first occurrence of $thing in @INC, where $thing could be a file or a directory.
I want the full path to the first match.

Here's my toy solution:

  $full_path = get_resource_by_name('File/Spec.pm');
  # /System/Library/Perl/5.8.6/darwin-thread-multi-2level/File/Spec.pm

  @full_paths = get_resource_by_name('File');
  # /System/Library/Perl/5.8.6/darwin-thread-multi-2level/File
  # /System/Library/Perl/5.8.6/File
  # /Library/Perl/5.8.6/darwin-thread-multi-2level/File
  # /Library/Perl/5.8.6/File


sub get_resource_by_name {
    my $path = shift;
    my @found = ();
    INC_ENTRY:
    foreach my $inc_entry (@INC) {
        if ( ref $inc_entry ) {
warn q{Don't know how to handle @INC entries of type: } . ref $inc_entry;
            next INC_ENTRY;
        }
        my $full_path = File::Spec->join($inc_entry, $path);
        if ( -e $full_path ) {
            if ( ! wantarray ) {
                return $full_path;
            }
            push @found, $full_path;
        }
    }
    wantarray ? return @found : return;
}


So, what is Best Way?

And how about those references in @INC?

-------------------------------------------------------
Matisse Enzer <[EMAIL PROTECTED]>
http://www.matisse.net/  - http://www.eigenstate.net/



Reply via email to