tonkin has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have code that says:
#!/usr/bin/perl -w
use strict;
use FindBin;
use lib("$FindBin::Bin/../lib/perl");
use Template;
where I have a new File::Spec (v0.8) installed in the $FindBin::Bin/../lib/perl directory and the old one (v0.6) in the regular Perl5 lib directory.

Template.pm uses File::Temp which requires the new version of File::Spec.

I would expect the

use lib
statement to force use of the newer version. It seems to Do The Right Thing to @INC, and the only Template.pm on the system is in the lnon-standard directory. But the program biffs because File::Temp (which is also in the non-standard dir!!) is loading.

Any clues?

Thanks,

Nick

Edited: ~Tue Jan 14 20:19:21 2003 (GMT) by footpad: Changed title, per Consideration; however, the title of the follow-up was used instead of the suggested retitle.

  • Comment on FindBin breaks dependency on File::Spec if using non-standard lib dir (WAS:@INC madness %$#%$#$@!)

Replies are listed 'Best First'.
FindBin breaks dependency on File::Spec if using non-standard lib dir (WAS: @INC madness %$#%$#$@!)
by tonkin (Initiate) on Jan 10, 2003 at 21:25 UTC
    To follow up: thanks to Tye for the clue:
    o My script used FindBin to determine its absolute path.
    o FindBin is standard with Perl, in my case 5.005_03.
    o FindBin (v1.42) does 'use File::Spec;'
    o File::Spec is standard with Perl.
    o Perl 5.005_03 has File::Spec v0.6
    o Many modules require File::Spec v0.8
    o I was doing 'use FindBin' to add my path to @INC,
      to load my custom File::Spec v0.8. But I thus had
      loaded the wrong version of File::Spec before modifying
      @INC.
    
    Tye pointed out that he has previously shown other ways in which FindBin can break, and has suggested a workaround using $0. This doesn't seem to provide a path that one can unshift onto @INC, though.

    Another suggestion has been to remove the loaded File::Spec from %INC, but it seems we have to worry about symbols we've exported. I've checked the source of File::Spec and it doesn't export anything by default. But it looks like FindBin calls all kinds of methods on it :(

    Meanwhile I'm hacking around with `pwd` but of course now I have to check that the user is in the right directory, but ... I still don't know where I am!!!!

    Continuing to look into this.