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:

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.