Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl - How do you type/execute/run Perl statements directly in the Perl shell/interpreter?

How do you type and then (execute/run) Perl statements directly in the Perl shell/interpreter?

First, I'm on Windows... and I have Strawberry Perl (v5.32.1) built for MSWin32-x64-multi-thread installed.

So, if I type at the command line, just :

perl

... it appears to enter into a Perl "shell/interpreter", but if I enter some Perl statements :

my $greeting = "Hello World :-)\n";
print($greeting);

... how do I make it then "execute/run" those two statements?

If I Ctrlc, then it just says: Terminating on signal SIGINT(2)

If it matters, the reason I'd like to do this is so that I can just test Perl language as I'm learning about Perl.

like image 937
George 2.0 Hope Avatar asked Sep 19 '25 05:09

George 2.0 Hope


2 Answers

Entering Ctrl + Z (final Enter still needed) corresponds to Ctrl + D on *nix and means End of file. You can also enter __END__.

like image 82
choroba Avatar answered Sep 23 '25 05:09

choroba


You can get a REPL using the debugger:

$ perl -d -e 1

Loading DB routines from perl5db.pl version 1.49
Editor support available.

Enter h or 'h h' for help, or 'man perldebug' for more help.

main::(-e:1):   1
  DB<1> x "blah" x 5
0  'blahblahblahblahblah'

Use x expression or p expression to evaluate an expression and display the result in different ways.

like image 32
Shawn Avatar answered Sep 23 '25 06:09

Shawn