Messed up Perl

Hal Vaughan hal at
Sun Oct 3 16:11:01 PDT 2010

On Oct 3, 2010, at 5:53 PM, Arno Hautala wrote:

> On Sun, Oct 3, 2010 at 14:55, Hal Vaughan <hal at> wrote:
>> I just found out that on my iMac, the "perl" command is now /opt/local/bin/perl and not /usr/bin/perl.
> That's because you installed perl with MacPorts.

So, if I understand, MacPorts basically says, "I'm so important that I'm going to override your default settings and take over Perl for your entire system."  Isn't that about the case?  (I'm commenting on that issue in MacPorts, I hope it doesn't sound like it's directed at you.)

>> 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."
> I'm not sure what the right way to clean that up is, but the proper
> way to install WWW::Mechanize would have been to run /usr/bin/cpan so
> that you were installing perl packages into the standard system, or to
> install the MacPorts version "p5-www-mechanize".

I tried this just before dinner and got it to work, but didn't have time to post it.  It hit me to just override the path and use /usr/bin/cpan -- also that if I'm specifying /usr/bin/perl in my script, then that script would not be using Perl in the /opt tree that MacPorts put in.  If that's the case, I realized I needed to use the version of CPAN from that directory.

>> So how do I either return Perl to "normal" so my Mac uses the regular Perl all the time, or make Perl use the modules in /opt/local/libs/perl5/site_perl?
> Using the system perl should be as simple as changing your shebang
> line.  (kerbang? Never heard it called that before.)

I've heard kerbang, shebang, and a few other variations.  I've been in some groups where if you use the wrong term they get rather offended.  I just use whichever term comes to mind.

> Short of cleaning up MacPorts (it'd probably be easiest to get a list
> of your installed ports, wipe the /opt directory, and reinstall) I'd
> switch your shebang line to point to the system perl (/usr/bin/perl)
> which shouldn't by default see the modules in /opt.  Then install
> Mechanize using the system CPAN (/usr/bin/cpan).  You could add the
> MacPorts directories to your @INC list (see below), but you may run
> into incompatibilities by trying to use different versions of perl and
> modules.

I'm not about to re-install MacPorts.  There are three programs I use: Kate, Konsole, and Amarok.  Konsole has a few simple differences that make it much better, for me, than Terminal and Kate was the first editor I started using when I started my own business and had to do all the programming, so it's still my favorite text editor for programming.  If it could do refactoring, it'd probably be my IDE, too.  (I do have a few complaints: No way to switch from editor to console from the keyboard is one.)

> Adding the below BEGIN block [1] to the beginning of your script will
> add the MacPorts perl modules to your INC variable.
> This will likely cause problems.  I get the following error [2] when
> importing WWW::Mechanize and running with /usr/bin/perl
> You'd be better off installing the appropriate port or installing from
> the system CPAN.
> [1]
> ###
>    push @INC,qw[
>        /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
>    ];
> }

I had experimented with this, but it didn't seem to work.  Not sure why.  I even put it in a BEGIN{} block, with the use function later, but it still got stubborn.  I must have had another glitch in it somewhere.

Thanks -- the best and easiest solution seems to be your first point: use /usr/bin/cpan and create the modules on my iMac from there, since I'm using perl from the same directory for my scripts.  Thanks for pointing that out, since I had not gotten to testing it and that certainly saved me some time!


More information about the macports-users mailing list