Downgrade perl version on mac - macos

First of all am new to MAC.
Am facing similar kind of issue on Mac where its shipped with V5.28.0 but i have to use perl V5.18.2 for my application. Have installed perl 5.18.2 using perlbrew install 5.18.2 and the installation was successful.
Have two questions here
Where are my default version and other version installed ? Is there any command to know them ? Have already tried checking echo $PATH but no use.
How to set the default version to 5.18.2 ?
Regards
AVK

The default installation location is
/usr/bin/perl
But that might not be where it's located on MacOS. You can find out for sure by running the following:
perlbrew off
which perl
(Restarting the terminal will reactivate perlbrew.)
The build you installed is in a directory under the directory returned by the following:
printf -- "%s\n" "${PERLBREW_ROOT:-$HOME/perl5/perlbrew}/perls"
You can modify the PATH so that perl runs the desired build using
perlbrew switch <name> # Changes it for this shell instance and those created later.
perlbrew use <name> # Changes it for this shell instance only.
You can get the names to use from
perlbrew list
See Switching to the system Perl using perlbrew for switching to the system Perl.
Scripts need to have the correct perl specified on their shebang (#!) line. Scripts installed by the standard Perl module installers will have this set correctly, but you'll need to edit the shebang (#!) line of scripts you've installed manually.

Another option (incompatible with perlbrew) is to use plenv. This lets you run different versions of perl for each directory. After installing with brew install plenv, you'd use it like so:
$ plenv install 5.18.2
$ cd project/needing/old/perl
$ echo "5.18.2" > .perl-version
Poof! Running perl in that directory or any of its subdirectories will use 5.18.2.
Note: if you run a perl script with ./script.pl, which has #!/usr/bin/perl, this should continue to use the perl installed at /usr/bin/perl. However, if the shebang line is /usr/bin/env perl, this should switch to the version specified by the .perl-version file.

Related

how to install and where to install bash bc on windows

I do not know how to install and where to install bc on windows
$ bash -help
GNU bash, version 4.4.23(1)-release-(x86_64-pc-msys)
$ bc
bash: bc: command not found
I use git-bash / mingw64 on windows.
please help
GIT Bash uses MINGW compilation of GNU tools. It uses only selected ones. You can install the whole distribution of the tools from https://www.msys2.org/ and run a command to install bc. And then copy some files to installation folder of Git. This is what you do:
Install before-mentioned msys2 package and run msys2 shell.
Install bc using the following command: pacman -S bc
Go to msys2 directory, for me it's C:\msys64\usr\bin
Copy bc.exe to your Git for Windows directory, for me this is C:\Users\\AppData\Local\Programs\Git\usr\bin
Why do you even need bc on a GIT bash?
A typical usage would be:
Prompt>echo $(1+2 | bc) // or something similar
Recently I've found out that double brackets do the thing, even without bc:
Prompt>$ echo $((1+2))
Prompt>3
Edit after first comment
In case you need floating point calculations, you might use awk, as in this example:
Prompt>awk 'BEGIN {print (20.0+5)/7}'
Prompt>3.57143
There are more examples under this URL.

Controlling what Perl considers the 'system shell'

I am running an externally supplied perl script (the OpenSSL configure script if you are interested). It contains the line:
my $vew=`nasmw -v 2>NUL`;
I am running on Windows, but I am using the version of perl which ships with git version 2.19.0.windows.1, and this appears to by a Cygwin perl which uses sh to execute backticks. The problem is that this creates a file called 'NUL' rather than throwing stderr away. Amongst other things you can't delete such a file from Explorer or the command line. (You can via bash).
I have read this question but setting PERL5SHELL to C:\Windows\System32\cmd.exe /C doesn't stop the file being created.
Is there a way of controlling the shell that a Cygwin perl uses?
Perl -v reports version 5.26.2
(The obvious workround is to patch NUL to /dev/null but I'd rather not do that if I can avoid it.)

cpan vs -MCPAN - Perl

I'm currently running bash via Cygwin on Windows, and I've come across two different ways to install a Perl module
cpan Name::Module
and
perl -MCPAN -e shell
install Name::Module
What's the difference between these two methods, and do they offer any advantages or disadvantages over the other?
cpan installs for the perl in the shebang (#!) line of the cpan file.
When someone has more than one perl installed on a machine, they sometimes run the wrong copy of cpan, and thus end up installing modules for the wrong instance of perl.
One solution to that would be to specify the full path to the correct cpan file.
perl -MCPAN -e shell is the other solution. It allows you to explicitly specify the install of perl for which you want the modules to be installed.
cpan on Windows just calls App::Cpan->run( #ARGV ), which should give you the same shell as the other command, maybe with other settings active. But I think it's the same. So you could use both. I prefer just cpan and then do install Name::Module, since I tend to look if it's installed before and which version in the cpan shell beforehand.

How can I make a Perl script executable in Windows 64bit?

I am trying to run the perl script through command line but it is not reorganizing the script file ie.
myscript.pl... is not working
but perl myscript.pl is working fine
I have tried the following suggestions but they didn't work either
How do I make my Perl scripts act like normal programs on Windows?
Perl execution from command line question
I am using Active Perl:- Perl 5 , Version 18.
It gives following warnings in both cases.
Using a hash as a reference is deprecated
earlier I installed strawberry perl before installing active perl, is that causing some problem.
The error message
Using a hash as a reference is deprecated
is a Perl message. Your script is being run just fine, but contains an error.
(It is remotely possible that you have two Perl versions installed, and that you configured Windows to use the wrong one. Reconfigure it to use the correct on then, using the guides you already found.)

How to use default path for ActivePerl 5.20 Mac OS X (/usr/bin/perl) instead of /usr/local/ActivePerl...?

I have installed ActivePerl 5.20.2 today on Mac OS X 10.9.5
Checking the version of perl in Terminal (perl -v) I see 5.20.2
So everything seems to be ok. But..
When I start my CGI scripts the script is running under built in perl (which is 5.16) (if using #!/usr/bin/perl).
If I use #!/usr/local/ActivePerl5.20.2/bin/perl then it runs under 5.20.2 that is required.
The question is: is it somehow possible to change the directory for using in my scripts from #!/usr/local/ActivePerl5.20.2/bin/perl to simple and familiar #!/usr/bin/perl keeping running under ActivePerl instead of built in.
I need to override the system's default version with the new ActivePerl.
I would be appreciated for your detailed answers (with name of files and directories where they are located) if ones are to be changed to implement salvation.
Thanks!
The question is: is it somehow possible to change the directory for using in my scripts from #!/usr/local/ActivePerl5.20.2/bin/perl to simple and familiar #!/usr/bin/perl keeping running under ActivePerl instead of built in.
Don't even try. That way lies damnation, not salvation. The ability to specify the specific interpreter that will handle your scripts is an important feature.
Instead, package your CGI script as a simple CPAN module. Then, install it using the familiar
$ /usr/local/ActivePerl5.20.2/bin/perl Makefile.PL
$ make install
routine. The shebang line will be automatically adjusted to reflect the perl that was used to build and install your package.
First, instead of specifying a particular path to your Perl interpreter in your script:
#! /usr/local/ActivePerl5.20.2/bin/perl
or
#! /usr/bin/perl
Specify this:
#! /usr/bin/env perl
This will find the first executable Perl interpreter in your $PATH and then use that to execute your Perl script. This way, instead of having to change your program, you only have to change the $PATH variable.
Next time, take a look at PerlBrew for installing a different version of Perl. PerlBrew will allow you to install multiple versions of Perl all under user control, and let you select which version of Perl you'd like to use.
I also recommend to put /usr/local/bin as the first entry in your $PATH. Then, link the executables you want to run to that directory. You can use something like this to create your links:
for file in $/usr/local/ActivePerl5.20.2/bin/*
do
basename=$(basename $file)
ln -s "$file" "/usr/local/bin/$basename"
done
This way, all programs you want to execute are in the same directory which makes setting $PATH so much easier. I even put /usr/local/bin in before /usr/bin and /bin because I want to be able to override the system's default version.

Resources