Score:0

Can Raku and Perl 5 Run on Same Ubuntu With Switching

im flag

I am using a desktop with Ubuntu 20.04. I have Perl 5 installed. I will be installing Raku. Before I install Raku, I want to make sure that I can switch between them, when running a Perl script.

Is it possible to have Raku and Perl 5 both installed and available on Ubuntu, with a switch script that will make one or the other the default Perl when running a script?

muru avatar
us flag
Does Raku even use the same command name as Perl?
NW7US avatar
im flag
I know that they are two different command-line commands. I was playing with the idea of using a shell alias such that I could switch between the two, when running the same process/script.
Score:1
jp flag

Yes, they are two completely different languages. Perl5 you will run it in scripts and command line as perl, and Raku as raku. There is no such switch, as the languages are not supported (although raku can run Perl code under certain conditions, Perl5 cannot run Raku code).

NW7US avatar
im flag
Knowing that Raku can run Perl5 code (within constraints), I was thinking of having a way to use Perl5 or Raku to run a script/process. What I have come to think as the best way to accomplish this is to create a shell alias that can be reset to either the Perl5 or Raku command-line, and just update the alias per need. If the script is engineered such that it can be run by either Perl5 or Raku, then I can choose either one. If there are unique differences I suppose I could set some environment variables to account for those differences. I've not yet completed my thought process on this.
Joaquín Ferrero avatar
jp flag
No, you have not understood. They are two VERY different languages, although they have some common details. But a script written in Raku will not be able to run in Perl5. It's like saying you want to write a script that can run in PHP and Python at the same time - you can't. In fact, it does not make sense unless you want to make a demonstration of intellectual virtuosity. If you write a script in Raku, you don't need to run it in Perl5. Just put #!/usr/local/bin/raku (or wherever the Rakudo interpreter is) on the first line, call it script.raku, and forget about Perl5.
Joaquín Ferrero avatar
jp flag
Please, see this example of Perl and Raku scripts for the same task: https://dzone.com/articles/perl-amp-raku-best-frenemies
NW7US avatar
im flag
Thanks for clarification. I was not clear in the scenario which had me contemplating this idea. I know Perl5 cannot run code targeting Raku. I was thinking of this scenario: I'm considering upgrading a software system over time to be completely Raku. Scripts I've written over decades are Perl5. I want to run the Perl5 scripts with Raku as the default for any Perl5 script in my system. I understand that there could be a necessary massage of those code files to fix issues like libraries. But, that would be a lot less initial work than re-writing every singles code file to be 100% Raku.
Joaquín Ferrero avatar
jp flag
If you remember, in Perl5 we usually use `system()` and `exec()` to execute an external command. You could use the same technique from Raku to run Perl scripts while rewriting them to Raku. According to the page [Perl to Raku guide](https://docs.raku.org/language/5to6-perlfunc) you can use the routine `run` (execute external command without using a shell) or `shell` (execute external command using a shell). Example: `run "perl", "script1.pl";`
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.