Placing entries at the end of @INC means that modules if found in the original @INC take precendence and are loaded instead of the ones you want loading. The chances are of such a case are slim but entirely possible especially if the user isn't aware of the perl module namespace.
I'm not sure why you are advocating adding to the back of @INC or how it relates to the thread, but adding to the front of @INC is definitely the way to go.
There are two reasons to add to @INC:
To have require locate a module that wouldn't get located otherwise. In this case, it doesn't matter if you add to the front or back of @INC since there's only one copy of the module.
To have require locate the prefered version of a newer module when require would have locate another version of the module otherwise. In this case, you need to add to the front of @INC.
So placing it at the front is claearly preferable. There are no reasons to place it at the back.
what if non-standard versions of ../strict.pm or ../warnings.pm existed?
You're inventing problems. If .. was added to the end of @INC, your non-standard strict.pm would never get loaded, so why did you write it?
Now back on topic,
eval "use Foo::Bar 5.01 qw| raz baz taz |"; # try loading v5.01 if ($@) { # if loading v5.01 failed warn "$@"; # fallback to using standard (v5.00) use Foo::Bar qw| baz |; # raz and taz arent valid tags here }
You still haven't addressed the problem I mentioned (and fixed) in my previous post. The second use will get executed first, and unconditionally. Since both use load the same module, all you'll get is a Subroutine baz redefined warning. However, it's skirting with danger.
Furthermore, it doesn't really make sense to import raz and taz from 5.01 if you don't create replacements when loading from <5.01.
BEGIN { require Foo::Bar; eval { Foo::Bar->VERSION(5.01) }; if ($@) { warn("Warning: Foo::Bar not desired version 5.01. " . "Proceeding anyway\n"); import Foo::Bar qw( baz ); *raz = sub { ... }; *taz = sub { ... }; } else { import Foo::Bar qw( raz baz taz ); } }
In reply to Re^4: BEGIN and compile-time
by ikegami
in thread BEGIN and compile-time
by jbert
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |