Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

How to run perl5.21.3 as "perl"

by syphilis (Bishop)
on Aug 18, 2014 at 10:39 UTC ( #1097821=perlquestion: print w/replies, xml ) Need Help??

syphilis has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I've installed current blead into ~/bleadperl.
There is no file named "perl" in ~/bleadperl/bin - instead it's called perl5.21.3, and I've been running scripts as 'perl5.21.3 script.pl', but that gets a bit tedious.
Also, when I inadvertently type 'perl script.pl' then the system perl gets invoked - and I certainly don't want to run *it*. So, I did this:
sisyphus-sis@debian-sis:~/comp/$ cd ~/bleadperl/bin sisyphus-sis@debian-sis:~/bleadperl/bin$ ln -s perl5.21.3 perl sisyphus-sis@debian-sis:~/bleadperl/bin$ cd ~ sisyphus-sis@debian-sis:~$ which perl /home/sisyphus-sis/bleadperl/bin/perl sisyphus-sis@debian-sis:~$ perl -le 'print $^X;' /usr/bin/perl sisyphus-sis@debian-sis:~$ echo $PATH /home/sisyphus-sis/bleadperl/bin:/usr/local/bin:/usr/bin:/bin:/usr/loc +al/games:/usr/games sisyphus-sis@debian-sis:~$ perl5.21.3 -le 'print $^X;' /home/sisyphus-sis/bleadperl/bin/perl5.21.3 sisyphus-sis@debian-sis:~$
I don't get it ... 'which perl' reports blead, but if I run 'perl' I still get the system perl. Why is that ?
I've also tried removing the 'perl' symlink in bleadperl/bin and, renaming 'perl5.21.3' to 'perl' - same thing happens:
sisyphus-sis@debian-sis:~/bleadperl/bin$ rm perl sisyphus-sis@debian-sis:~/bleadperl/bin$ which perl /usr/bin/perl sisyphus-sis@debian-sis:~/bleadperl/bin$ mv perl5.21.3 perl sisyphus-sis@debian-sis:~/bleadperl/bin$ which perl /home/sisyphus-sis/bleadperl/bin/perl sisyphus-sis@debian-sis:~/bleadperl/bin$ perl -le 'print $^X;' /usr/bin/perl
So now I've renamed ~/bleadperl/bin/perl back to ~/bleadperl/bin/perl5.21.3:
sisyphus-sis@debian-sis:~/bleadperl/bin$ mv perl perl5.21.3 sisyphus-sis@debian-sis:~/bleadperl/bin$ cd ~ sisyphus-sis@debian-sis:~$ which perl /usr/bin/perl sisyphus-sis@debian-sis:~$ perl5.21.3 -le 'print $^X' /home/sisyphus-sis/bleadperl/bin/perl5.21.3
and I guess I'll just have to continue calling it as 'perl5.21.3' until I can find a way to call it as 'perl'.

I've also checked that I don't have to call it precisely 'perl5.21.3' - eg I can call it 'perlzzz' and it's still runnable.
But I can't run it as 'perl'.

Cheers,
Rob

Replies are listed 'Best First'.
Re: How to run perl5.21.3 as "perl"
by aitap (Curate) on Aug 18, 2014 at 11:38 UTC
    In bash, sometimes you need to run hash -r when you change contents of your $PATH directories, otherwise you will encounter "file not found" for files which should be found in other directories and similar errors.
Re: How to run perl5.21.3 as "perl"
by wjw (Priest) on Aug 18, 2014 at 11:34 UTC

    Is Perlbrew not an option for you? If it is, I would recommend it. Takes the head-scratching out of having multiple Perls on my machine and prevents me having to worry about messing up the system Perl.

    Just a thought...

    ...the majority is always wrong, and always the last to know about it...

    Insanity: Doing the same thing over and over again and expecting different results...

    A solution is nothing more than a clearly stated problem...otherwise, the problem is not a problem, it is a facct

Re: How to run perl5.21.3 as "perl"
by tobyink (Canon) on Aug 18, 2014 at 11:06 UTC

    I don't know exactly what's causing the problem, but a workaround might be to set up a shell alias. Most Unix shells (bash, tcsh, etc) support them, though the syntax to define them varies from shell to shell, so you'd need to check your shell's manual.

      I was half expecting it might have been something obvious that I was missing.
      Something in your reponse made me suddenly think "hang on ... I'm doing this over an ssh connection". So I decided to see whether the same problem existed when I sat at the computer's terminal (using identical path) and accessed it directly ... and it didn't !! Everyting works as expected when I'm sitting at the terminal.

      But what makes it even weirder is that I have other perls under ~, and those perls *are* accessible as "perl" over the ssh connection.
      For example:
      sisyphus-sis@debian-sis:~$ echo $PATH /home/sisyphus-sis/perl520-m64-multi/bin:/usr/local/bin:/usr/bin:/bin: +/usr/local/games:/usr/games sisyphus-sis@debian-sis:~$ which perl /home/sisyphus-sis/perl520-m64-multi/bin/perl sisyphus-sis@debian-sis:~$ perl -le 'print $^X' /home/sisyphus-sis/perl520-m64-multi/bin/perl sisyphus-sis@debian-sis:~$
      No problems with that (or any of the 7 other installations of) "perl" over the ssh connection. It's just the bleadperl that won't play ball.
      Thanks for the reply tobyink

      Cheers,
      Rob
Re: How to run perl5.21.3 as "perl"
by Corion (Pope) on Aug 18, 2014 at 11:35 UTC

    Are you certain that you don't have a shell alias for perl, which points to /usr/bin/perl?



      Are you certain that you don't have a shell alias for perl, which points to /usr/bin/perl?


      I think that if that was the case then the other 7 perls that I have installed also under my home directory would be likewise affected ... but they're not.

      Cheers,
      Rob
Re: How to run perl5.21.3 as "perl"
by ikegami (Pope) on Aug 18, 2014 at 22:01 UTC

    which is a utility rather than a shell command in sh and sh-derived shells. As such, it knows nothing of the shell's aliases and such. It just searches the path.

    To find out what bash will execute when you type perl, use type perl. It will tell you if it's an alias. It will tell you if it's "hashed", which is to say cached. The cache can be cleared using hash -r.

    Update: Added "in sh and sh-derived shells".

      bash doesn't have a built-in which? tcsh does, which is quite handy...

      $ which perl /home/tai/perl5/perlbrew/perls/perl-5.20.0/bin/perl $ which ls ls: aliased to ls --color=tty $ which which which: shell built-in command.

        You seem to have stopped reading my post before the second paragraph. The whole point of my post was to show how to do what tcsh's which does.

        $ type perl perl is /home/ikegami/usr/perlbrew/perls/5.20.0t/bin/perl $ perl -e1 $ type perl perl is hashed (/home/ikegami/usr/perlbrew/perls/5.20.0t/bin/perl) $ type ls ls is aliased to `ls -F -1 --color=auto' $ type type type is a shell builtin
Re: How to run perl5.21.3 as "perl"
by syphilis (Bishop) on Aug 18, 2014 at 14:48 UTC
    Well ... having created the perl5.21.3->perl symlink from the terminal (as opposed to over the ssh network connection), I left that symlink in place.
    That didn't make any difference to my existing ssh connection immediately - I still had 'which perl' reporting blead, but 'perl' loading the system perl. However, after a few path changes to run different perls, all suddenly started working perfectly when I came back to using blead over the ssh connection. Out of the blue, 'which perl' reported blead (as before) but 'perl' now loaded blead instead of the system perl.

    Buggered if I know what the problem was, or what the solution was, but I'll try to re-create the problem next time I build blead.
    If I can find something definitive, I'll update this thread with the info.

    Thanks guys.

    Cheers,
    Rob

      The problem encountered, and the solution to it, is already acknowledged by aitap couple posts above.

      When you enter a command, the shell has to successively perform a number of stat calls, each with a $PATH element (a directory) prepended. In order to cut down on those syscalls, a small short-circuiting cache is kept. In perl parlance, this would be $full_path{$name}.

      You can check the current state of path cache with the "hash" builtin. To clear the cache, enter "hash -r". To refresh the cache on a particular command, try e.g. "hash perl".

        To clear the cache, enter "hash -r".

        Ok - sounds like that must have been the problem.
        Odd that it hasn't bitten me before - but this is the first fix I'll try if it recurs.

        Acknowledgements to aitap, oiskuu and ikegami for raising/pressing this point.

        Cheers,
        Rob
        This probably made sense back in the good old days when disks were slow and memory expensive so you couldn't cache much. These days, it's a misfeature verging on being a bug. And I don't think it can even be disabled.
Re: How to run perl5.21.3 as "perl"
by Anonymous Monk on Aug 18, 2014 at 12:42 UTC
    The "files" in /usr/bin are often symbolic links ...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1097821]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2020-11-27 05:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?