4

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!

1
  • 4
    I use perl -C -dwE 1 to invoke the interactive Perl debugger, but it's a bit crude. For example, my $x = 42 won't be remembered on the next line. Drop the my and it works. Commented Jun 11, 2018 at 17:51

1 Answer 1

10

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Sadly, neither Devel::REPL nor Reply are under active development. The last stable releases for both are over four years old. This is code rot in action, folks.
@CecilCurry well volunteered! :) // but to be fair, both of them are stable. You don't always need to keep developing stuff.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.