Ahdee
Ahdee

Reputation: 4949

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!

Upvotes: 4

Views: 1060

Answers (1)

simbabque
simbabque

Reputation: 54333

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.

Upvotes: 10

Related Questions