I have script that makes heavy use of temp files, developed on a Perl 5.6.1 system. Not suprisingly, I use the File::Temp module to make life simpler and safer. Now I need to make things run on older systems (e.g., 5.005_03).

The first thing I need to do is add File::Temp to the older system, since it didn't become a core module until 5.6.1. I also need to add an updated version of File::Spec, since Perl 5.005_03 includes 0.6 and File::Temp wants 0.8. As I can't muck about with the system's Perl installation, I need to install these modules into a local directory I can access.

So my code looks something like this:

#!/usr/bin/perl -w use strict; use FindBin; use lib "$FindBin::Bin/../lib/perl"; use File::Temp qw(tempfile); # ... remainder snipped ...

Obviously, I've installed the modules into a "cousin" directory at the same level as the script, hence the use of FindBin. But when I run the script, it generates the following type of error:

File::Spec version 0.8 required--this is only version 0.6 at /wonko/sh +are/jwd/lib/perl/File/Temp.pm line 124. BEGIN failed--compilation aborted at /wonko/share/jwd/lib/perl/File/Te +mp.pm line 124. BEGIN failed--compilation aborted at ./foo line 34.

If I toss the "use FindBin;" statement and hardcode the "use lib ...;" statement to a particular path, then all is well. But unfortunately, as I can't predetermine where this will be installed, I really need the FindBin (or something like it).

What seems to be happening is that the system's default (0.6) version of File::Spec is being pulled in by the "use FindBin;" statement (I checked FindBin.pm and it does use File::Spec), effectively masking the local (0.8) version I've so carefully installed into my local "../lib/perl" directory.

So how do I get around this? Is there any method to force Perl to flush (or some such thing) all loaded modules after the "use lib ..." statement? Other alternatives? Setting the PERL5LIB environment variable before invoking the Perl script would work, I guess, but that's a bit much to ask in this environment.


In reply to Forcing use of newer (local) version of core module by jwd

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.