From: "Chris Nehren" <c.nehren/beginn...@shadowcat.co.uk>
Subject: Re: Using perlbrew to change Perl version for scripts
On Sat, Jun 02, 2012 at 12:57:22 -0400 , Shawn H Corey wrote:
On 12-06-02 12:23 PM, sono...@fannullone.us wrote:
> Is it possible to use a shebang line, like #!/usr/bin/env perl, so
> that scripts will use the currently selected version of Perl with
> perlbrew? According to the help, it appears that perlbrew only
> changes the version for the CLI:
>
>
>COMMAND: SWITCH
> Usage: perlbrew switch [<name> ]
>
> Switch to the given version, and makes it the default for this and
> all
> future terminal sessions.
>
>
> Right now, I'm hardcoding the version of Perl in my scripts, like:
>
>#!/Users/marc/perl5/perlbrew/perls/perl-5.16.0/bin/perl
>
>but it's an inconvenience to change the shebang line in all my
>scripts just to try a different version. It would be nice if
>perlbrew took care of that as well.
>
> It seems like it should do this automatically, so maybe I don't have
> something set up correctly, but googling hasn't helped.
>
>Thanks,
>Marc
I don't know anything inside perlbrew that will help, but you could do
this:
sudo ln -s /Users/marc/perl5/perlbrew/perls/perl-5.16.0/bin/perl
/usr/local//bin/perl
Then change your shebangs to: #!/usr/local/bin/perl
This has the advantage of not having to run your profile to get the
correct version of perl and when you upgrade, you just have to change
the symlink to upgrade all your scripts.
And the disadvantage of clobbering whatever's in /usr/local/bin/perl,
defeating the point of perlbrew in the first place.
Don't do that.
Yes, the `#!/usr/bin/env perl` shebang should do. I've used it with
perlbrew myself.
--
Chris Nehren | Coder, Sysadmin, Masochist
Shadowcat Systems Ltd. | http://shadowcat.co.uk/
Yes I also use that way with Perlbrew and it works fine even for the jobs
run by cron.
So the beginners shouldn't be confused by telling them that Perlbrew can't
be used to run cron jobs.
When using the
#!/usr/bin/env perl
shebang line, the program runs with the first perl installation found in
PATH, so the user just needs to ensure that the wanted installation of Perl
is in PATH and that its lib directories are set in the PERL5LIB environment
variable.
So for running cron jobs with a version of Perl installed by Perlbrew, I
just needed to add the following lines at the start of cron script:
PERL5LIB=/home/teddy/perl5/perlbrew/perls/perl-5.14.2/lib/site_perl/5.14.2:/home/teddy/perl5/perlbrew/perls/perl-5.14.2/lib/5.14.2
PATH=/home/teddy/perl5/perlbrew/bin:/home/teddy/perl5/perlbrew/perls/perl-5.14.2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
That's all.
The advantage is that when you'll install a new version of Perl with
Perlbrew, you will just need to change 2 lines in cron, and not all the Perl
programs.
Octavian
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/