How to override system commands in shells initiated by Perl? - perl

I am trying to install CPAN modules on shared Linux environment without root privileges, and in particular the PDL::Graphics::Gnuplot module. The default gnuplot version is Version 3.7 patchlevel 3, but the version Version 4.6 patchlevel 3 is also installed (/opt/gnuplot-4.6.3/bin/gnuplot). When trying to install the Perl module in my local directory, it fails on the test:
unless(`gnuplot -V`)
I tried to override the default gnuplot command with an alias in .bashrc:
alias gnuplot='/opt/gnuplot-4.6.3/bin/gnuplot'
In the regular shell I get:
$gnuplot -V
gnuplot 4.6 patchlevel 3
But using Perl:
$ perl -e 'system("gnuplot -V")'
Cannot open load file '-V'
line 0: (No such file or directory)
How do I make Perl to see the new version of gnuplot?
On solution I think of is to change the system command in the Makefile and in the following files in the module.

Shell aliases only work in the interactive shell. You have other options:
Change your PATH so that the newer gnuplot's bin precedes the old one.
Make a symbolic link to the new gnuplot from your bin and make sure it comes first in PATH.

Related

Steps to install perl version 5.26.3 in Solaris 11 Host

I would like to install perl version 5.26.3 in host running with Solaris 11 using service account. The installation has to be done in Application file system or in user directory.
Please could someone share with the steps to install ?
Please note that perl 5.26 version is already installed at OS level , but we want to have our own perl installation in application folder rather than using OS level perl interpreter
Thanks.
Here is an example of installing from source using the defaults. If you want to modify the defaults, have a look at the INSTALL document.
$ wget https://www.cpan.org/src/5.0/perl-5.26.3.tar.bz2
$ bunzip2 perl-5.26.3.tar.bz2
$ tar xvf perl-5.26.3.tar
$ cd perl-5.26.3
$ sh Configure -de -Dprefix='/some/dir' # Where to install
$ make
$ make test
$ make install
Then edit the PATH environment variable to include /some/dir/bin such that the shell can find the new perl.

Tcl call in perl script

I am executing a Perl script that makes use of use Tcl;. This currently invokes tcl8.4.
When I check my lib path, tcl8.5 is also found. I want use Tcl; to use tcl8.5 instead of tcl8.4. Can any one help me please?
From looking at the distro's Makefile.PL, I believe it uses a tclshX.Y found when the module is installed.
If a newer version 8.5 of Tcl has been installed since you installed the module, you could try to reinstall the module.
wget https://cpan.metacpan.org/authors/id/V/VK/VKON/Tcl-1.27.tar.gz
tar xvzf Tcl-1.27.tar.gz
cd Tcl-1.27
perl Makefile.PL
make test
make install
If that isn't sufficient, this module's Makefile.PL accepts arguments that help locate the correct tclsh. As mentioned in the distro's README file, you can see the accepted options using the following:
perl Makefile.PL --help

How can I control the Java version used with Ammonite

In my Linux system I have several Java versions installed.
How can I control the version used to launch an Ammonite script?
The amm executable is a sh script.
It searches java in the PATH.
So you can change temporarily your PATH. In bash it can be done in this way:
PATH=/path/to/java myscript.sc argument1 argument2 ....

How to force MATLAB 2016a to use gcc-4.7.x instead of the one I have (gcc-5.4.1)?

There are some posts about this for the older releases of MATLAB, but they don't seem to work for R2016a.
I'm trying to install MatConvNet on Ubuntu 16.04. When I run the vl_compilenn command as described here, it gives me a warning as follows:
Building with 'gcc'.
Warning: You are using gcc version '5.4.1'. The version of gcc is not supported.
The version currently supported with MEX is '4.7.x'. For a list of currently supported
compilers see: http://www.mathworks.com/support/compilers/current_release.
I have already installed gcc-4.7 and g++-4.7 using apt-get install gcc-4.7 g++-4.7. How can I force MATLAB to use these versions and not the default ones?
Few hints, not a complete tutorial how to do it.
Probably the simplest would be to edit the MATLAB's Mex XML configuration file:
mex -setup C
cc = mex.getCompilerConfigurations('C', 'Selected')
edit(cc.MexOpt)
The mex setup usually creates a copy in your home folder (~/.matlab/<version>/mex_C_glnca64.xml), so you should be able to edit it without root.
There you probably need to change the section:
<GCC>
<cmdReturns name="which gcc" />
</GCC>
which I guess searches for the location of the gcc command to your gcc version and assigns it to the $GCC variable. Plus you can change the version name in the header.
Additionally you need to do the same for the C++ language.
This works with R2016b:
Install the required GCC version with apt install (gcc-4.9 and g++-4.9 in my case).
Create a bin folder in your home, i.e. ~/bin.
Create the following links with ln:
ln -s /usr/bin/gcc-4.9 ~/bin/gcc
ln -s /usr/bin/g++-4.9 ~/bin/g++
If using CUDA, create a file called nvcc in the ~/bin folder, with the following contents (don't forget to make it executable: chmod +x ~/bin/nvcc):
Contents:
#!/bin/sh
exec /usr/lib/nvidia-cuda-toolkit/bin/nvcc -ccbin gcc-4.9 "$#"
If necessary replace /usr/lib/nvidia-cuda-toolkit/bin/nvcc with the correct location of the nvcc binary.
Open MATLAB and follow the instructions for compiling MatConvNet.

How to set properly SCALA_HOME in a macport installed scala

I have installed multiple versions of Scala (2.9 and 2.10) on my mac (OS X 10.7.5) using macports. I like this way because can switch easily between these two versions by the simple "port select" command.
But, the SCALA_HOME environment variable does not get set automatically with this command.
Is there a proper nice macport command to set correctly the SCALA_HOME variable?
If no, what directory should the SCALA_HOME point to in a macport installed scala?
Thanks
EDIT:
Until now the best way I found is with a shell script that looks what is the current scala command and adjust the SCALA_HOME variable accordingly. I run it always after switching the Scala version.
Here is the important command in the script. I'm not an expert shell programmer, therefore I'll be thankful for any suggestion:
export SCALA_HOME=$(ls -l `which scala` | gawk 'match($0, "(/opt/local/share/.*)/bin/scala", a) {print a[1]}')
I don't know of a way to have MacPorts do it for you, but Scala is installed at /opt/local/share/scala-2.10/ for me. So I added
export SCALA_HOME="/opt/local/share/scala-2.10/"
to my ~/.profile and everything seems to be working for me now (although you'd have to switch change your $SCALA_HOME every time you switch versions).
OK, until now the best solution I found is to run following command after changing scala version:
export SCALA_HOME=$(ls -l `which scala` | gawk 'match($0, "(/opt/local/share/.*)/bin/scala", a) {print a[1]}')
I have included that command also in my .bash_profile so my SCALA_HOME always points to the scala version I am using currently.
This command uses gawk 4.1.1 installed from MacPorts.
Currently when scala is installed via brew it's path set to
/usr/local/Cellar/scala/[version]
So SCALA_HOME could be defined as follows:
export SCALA_HOME=$(greadlink -f $(dirname "$(greadlink -f $(which scala))")/../../)
p.s: You need to install 'greadlink' for that since the regular readlink doesn't support the 'f' flag.
if you are installing the versions with home brew you can simply:
brew switch scala 2.10.3