develooper Front page | perl.perl5.porters | Postings from April 2000

Re: %INC...

Thread Previous
From:
Tom Christiansen
Date:
April 29, 2000 12:18
Subject:
Re: %INC...
Message ID:
8067.957035862@chthon
>Would it be sensible to patch %INC such that keys could also be package
>names?  This way, I can do:

>  use Some::Module;
>  $loc = $INC{'Some::Module'};

That's not good.  You're conflating too many things.  I can write

    do "Some::Module"

just fine, thank you very much, and it will search my @INC path for
that name.  You can't autocollapse those because all the files
that Perl loads are *not* modules.

  DB<1> use charnames ":full"; $x = "\N{GREEK SMALL LETTER EPSILON}"
  DB<2>  x \%INC
0  HASH(0xa90cc)
   '/home/tchrist/.perldb' => '/home/tchrist/.perldb'
   'Carp.pm' => '/usr/local/lib/perl5/5.6.0/Carp.pm'
   'Exporter.pm' => '/usr/local/lib/perl5/5.6.0/Exporter.pm'
   'Term/Cap.pm' => '/usr/local/lib/perl5/5.6.0/Term/Cap.pm'
   'Term/ReadLine.pm' => '/usr/local/lib/perl5/5.6.0/Term/ReadLine.pm'
   'bytes.pm' => '/usr/local/lib/perl5/5.6.0/bytes.pm'
   'charnames.pm' => '/usr/local/lib/perl5/5.6.0/charnames.pm'
   'dumpvar.pl' => '/usr/local/lib/perl5/5.6.0/dumpvar.pl'
   'perl5db.pl' => '/usr/local/lib/perl5/5.6.0/perl5db.pl'
   'unicode/Name.pl' => '/usr/local/lib/perl5/5.6.0/unicode/Name.pl'

And who's do say I didn't say require "Foo/Bar.pm" anyway?  Or what
*that* is supposed to mean?  It would be wrong if on systems with 
a proper filesystem, that that would cause a redundant load.

>instead of doing:

>  use Some::Module;
>  $OSSEP = '/';
>  for ($^O || do { require Config; $Config::Config{osname} }) {
>    /Win/i and $OSSEP = '\\', last;
>    /^MacOS$/i and $OSSEP = ':', last;
>    /os2/i and $OSSEP = '\\', last;
>  }
>  ($module = 'Some::Module.pm') =~ s/::/$OSSEP/g;
>  $loc = $INC{$module};

>But perhaps I'm being silly.

The simple solution: don't be used by an "operating system" where
it makes a difference.

--tom

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About