Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: How should I manage CPAN when using two versions of Perl in my computer?

by bliako (Monsignor)
on Jun 18, 2018 at 10:53 UTC ( [id://1216845]=note: print w/replies, xml ) Need Help??


in reply to Re: How should I manage CPAN when using two versions of Perl in my computer?
in thread How should I manage CPAN when using two versions of Perl in my computer?

I have the exact same situation with OSX: there is a native perl that system relies on and my own updated version. perlbrew was the way to go for me.

Now, use of perlbrew, requires to set an env-var and use #!/usr/bin/env perl as the shebang of all your perl scripts. Do you have to mess with system's perl scripts, or Apache's etc. and change their shebangs to this new env thingy? Most likely no. This is just a warning from me and very likely a false alarm!

Because from my experience on OSX, I use perlbrew but the system still uses its own perl without me ever needed to mess with system's shebangs. So, in my case perlbrew works as I and the system expect it, but you should confirm that perlbrew will not require you to change anything in system's perl scripts neither require Apache or cron or whatever to setup perlbrew-specific env-vars.

Btw, this came up in a search : https://stackoverflow.com/questions/4764025/how-to-specify-which-version-of-perl-to-use-on-centos

Second caveat is of course the use of perl-command switches in the shebang (e.g. #!/usr/bin/perl -w). You will find that your new shebang #!/usr/bin/env perl -w does not work in linux (expected behaviour, you must remove the '-w' at the end and find a way to put it somewhere else. Where? Someone knows a definite guide on this?) but works in OSX (BSD-based), see here: shebang anomaly

Once using perlbrew, you may also want to install modules using cpanm (App::Cpanminus) rather than cpan. Great program! Transparent and efficient: cpanm install Test::More

Alternatively and for the sake of completeness, I mention update-alternatives. It is the linux-specific way to handle multiple versions of the same program, e.g. gcc. I have used it with gcc and java and never had any problem. Though I never bothered to learn more about it than copy-paste some one-liners from net. I assume it can handle all these because gcc/java, just like perl, rely on other programs, libraries, installation paths etc.

Replies are listed 'Best First'.
Re^3: How should I manage CPAN when using two versions of Perl in my computer?
by atcroft (Abbot) on Jun 25, 2018 at 20:05 UTC

    Regarding the "shebang anomaly", perlrun indicates that:

    • -w
      prints warnings about dubious constructs, such as variable names mentioned only once and scalar variables used before being set; redefined subroutines; references to undefined filehandles; filehandles opened read-only that you are attempting to write on; values used as a number that don't look like numbers; using an array as though it were a scalar; if your subroutines recurse more than 100 deep; and innumerable other things.
      This switch really just enables the global $^W variable; normally, the lexically scoped use warnings pragma is preferred. You can disable or promote into fatal errors specific warnings using __WARN__ hooks, as described in perlvar and warn. See also perldiag and perltrap. A fine-grained warning facility is also available if you want to manipulate entire classes of warnings; see warnings.

    I would think if you update the script to use warnings you should be okay in removing the '-w' from the shebang line (although if I am wrong, please respond, so I can learn from the mistake!).

    Hope that helps.

Re^3: How should I manage CPAN when using two versions of Perl in my computer?
by usemodperl (Beadle) on Jun 30, 2018 at 17:50 UTC
    use of perlbrew, requires to set an env-var and use #!/usr/bin/env perl as the shebang of all your perl scripts.

    I love perlbrew but I love the shebang more. I could not look at env at the top of every perl script let alone type it. Shebang is holy and I found an easy way to preserve it to an acceptable degree and gained a very handy perlbrew switch. Like many others I have an untouched system perl and a main perlbrew with tons of cpan modules. My shebang preservation and toggle switch between system perl and perlbrew perl is achieved by making a symlink in the root directory called "user" that points to the main perlbrew path:
    
    cd /
    sudo ln -s /path/to/perl5/perlbrew/perls/perl-VERSION user
    
    
    The main perlbrew path is found by typing "which perl" while brewing the main perlbrew perl and ignoring the /bin/perl part at the end. Now there are two shebangs with a single character switch that works everywhere:
    
    #!/usr/bin/perl  # system perl
    #!/user/bin/perl # perlbrew perl
    
    
    On my system:
    
    /usr/bin/perl -le 'print $^V'
    v5.18.2
    
    /user/bin/perl -le 'print $^V'
    v5.26.2
    
    
    This symlink has made me very happy! ☺

    STOP REINVENTING WHEELS, START BUILDING SPACE ROCKETS!CPAN 🐪

      Thinking about it you can do this:

      % sudo ln -s /path/to/perl5/perlbrew/perls/perl-VERSION use$'\x010'r % echo /* /usr /usr

      It introduces a backspace in the filename of 'user' just after 'e'.

      but don't try it at home ... neither at work

        Getting rid of that symlink left as an exercise for the reader ...

      neat

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1216845]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-04-19 14:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found