Messed up Perl

Jon Hermansen jon.hermansen at gmail.com
Sun Oct 3 16:25:27 PDT 2010


Better late than never, I wrote this earlier but never sent it along...


> I just found out that on my iMac, the "perl" command is now
> /opt/local/bin/perl and not /usr/bin/perl.  Now maybe that's not a big
> issue, since I have a kerbang at the start of all my scripts, but there's
> more of a problem.
>

You probably want to modify your PATH environment variable, or start
overriding your shebang line by not running it like this:

./foo.pl
>

You can pick and choose which Perl you want to use at runtime by providing
the complete path to Perl, so given your program foo.pl, you can run either:

/usr/bin/perl foo.pl
/opt/local/bin/perl foo.pl

and run it with whichever version of Perl you like.

I ran CPAN to install WWW::Mechanize and it's in
> /opt/local/libs/perl5/site_perl and I can't include them in my script with
> "use WWW::Mechanize."
>

This is completely normal if you ran /opt/local/bin/cpan and not
/usr/bin/cpan, but try to use /usr/bin/perl to execute your program. If you
want to install Perl modules for the Apple-provided version of Perl, you
need to run CPAN by running /usr/bin/cpan. If you don't mind using MacPorts'
perl, why not just 'port install p5-www-mechanize' ? It's already been
packaged as port, and you don't need CPAN to use it, plus you get all the
awesome functionality that 'port' provides.


> So how do I either return Perl to "normal" so my Mac uses the regular Perl
> all the time


Remove /opt/local/bin from your PATH. In a terminal:

yawn-lappy:~ jhermansen$ echo $PATH
>
> /opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
> yawn-lappy:~ jhermansen$ which perl
> /opt/local/bin/perl
> yawn-lappy:~ jhermansen$ perl -e 'print $ENV{'_'}, "\n";'
> /opt/local/bin/perl
>
> yawn-lappy:~ jhermansen$ export
> PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin"
> yawn-lappy:~ jhermansen$ which perl
> /usr/bin/perl
> yawn-lappy:~ jhermansen$ perl -e 'print $ENV{'_'}, "\n";'
> /usr/bin/perl
>

FYI, MacPorts has a post-install script that modified your PATH so you may
want to revert that, see:
http://guide.macports.org/#installing.shell.postflight

More information on $PATH + 'which':
http://www.linux-tutorial.info/modules.php?name=MContent&pageid=329

You can also immediately remove all MacPorts-installed versions of Perl by
running 'sudo port -f uninstall perl5 perl5.8 perl5.10 perl5.12' if you so
choose.


> or make Perl use the modules in /opt/local/libs/perl5/site_perl?
>

You can try this too by modifying the PERL5LIB environment variable, though
you may have the least success trying this...

PERL5LIB="/opt/local/lib/perl5/site_perl"

But you should also know that the MacPorts-provided version of Perl has many
other directories by default in @INC, which is an array built from $PERL5LIB
in your environment, and paths hard coded into the perl binary.

  @INC:
>     /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level
>     /opt/local/lib/perl5/site_perl/5.8.9
>     /opt/local/lib/perl5/site_perl
>     /opt/local/lib/perl5/vendor_perl/5.8.9/darwin-2level
>     /opt/local/lib/perl5/vendor_perl/5.8.9
>     /opt/local/lib/perl5/vendor_perl
>     /opt/local/lib/perl5/5.8.9/darwin-2level
>     /opt/local/lib/perl5/5.8.9
>     .


And you can also modify @INC by putting

use lib '/opt/local/libs/perl5/site_perl';
>

in your script. I think you can also do:

use lib qw[
>
    /opt/local/lib/perl5
>
    /opt/local/lib/perl5/blah ...
>
];
>

which may work better than directly modifying @INC like Arno mentioned.

More information on PERL5LIB:
http://perldoc.perl.org/perlrun.html#ENVIRONMENT

Long story, I know... HTH.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-users/attachments/20101003/1a990a5f/attachment.html>


More information about the macports-users mailing list