Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an interactive command line environment for Perl?

Hi I'm wondering if there is something for Perl similar to Rstudio? That is to ability to run commands, retain all variables in memory without exiting the script.

For example say I execute this command my $temp = 83; then instead of ending the script I change the value $temp = 22; print "$temp \n"; and so on, but I don't end the script and continue to work on it. This will be extremely helpful when dealing with a large datasets and general workflow. The closest thing I came across is Visual Studio Code using a plugin whereby I can execute specific chunks of code in my script. However I did not find a way to keep the variable persistently in memory.
thanks!

like image 543
Ahdee Avatar asked Dec 23 '22 06:12

Ahdee


1 Answers

You want a REPL.

Take a look at Devel::REPL. It brings a script called re.pl that you can run.

$ re.pl
$ my $foo = 123;
123$ use feature 'say';
$  $foo + 1;
124$ 

A newer alternative is Reply with its reply script.

$ reply 
0> my $foo = 123;
$res[0] = 123

1> $foo + 2
$res[1] = 125

2> 

For a comparison, you can read this blog post by Matt Trout.

like image 180
simbabque Avatar answered Mar 03 '23 18:03

simbabque