7

I'm trying to use IntelliJ Idea to work on a perl script. I installed the perl plugin for IDEA as well as Strawberry Perl for Windows (10).

The syntax highlighting and other features work, but this is what happens when I try to run the program:

Running the Program

I'm a beginner at perl, so I'm still just using command line stuff and ASCII graphics. I was hoping to simply run, test, and debug my perl programs in IntelliJ, but the print statement isn't putting anything in this dialog when perl runs...

I can still type stuff in the above image where the cursor is, and typing the wrong stuff can throw errors as it is supposed to. So <STDIN> seems to be properly mapped, but <STDOUT> is not? Or is something else wrong?

If I copy the command that it shows it is running to cmd, it works perfectly:

Mancala working

So is there a way to configure intellij to get <STDOUT> in this dialog? Any help would be appreciated.


Now, following Chankey's answer, I've made a test script, and that one works:

Test.pl working

Maybe the problem is that I imported the perl file from an external source, and IntelliJ doesn't realize it is a script, or something like that? But if I copy the code into the new file, it doesn't work either...

The test.pl had one difference: use warnings FATAL => 'all'; instead of use warnings;. When I try this, it works until I type a string where numeric input is expected, and then prints a whole bunch of what it should have been printing all along as it quits the program:

Some of the output shown now

Again, the output works fine in cmd, so I think this is an issue with IntelliJ. Any ideas? Maybe the @ symbols are creating issues? Something else? If anyone uses IDEA for windows and wants to toy around with my code, it's available on github.

Menasheh
  • 3,560
  • 3
  • 33
  • 48
  • `print "stuff" ` does go to STDOUT, right? – Menasheh Oct 06 '16 at 04:52
  • General syntax of print is `print FILEHANDLE LIST`. If FILEHANDLE is omitted, then it prints to the last selected (see select) output handle. So unless you have changed FILEHANDLE using `select` then it will print to default FILEHANDLE which is STDOUT. – Chankey Pathak Oct 06 '16 at 05:52

2 Answers2

2

Works fine for me. Below are the steps:

  1. Create a project
  2. Right click on project and select New, then select Perl5 file
  3. Give a name to file and select Script from dropdown
  4. Write your script, save it
  5. Press CTRL+SHIFT+F10
  6. Provide some data as user input then press Enter

Output:

enter image description here

If it still does not work for you then perhaps you have not setup your Perl properly.

Go to File->Project Structure and add perl to Project SDK.

enter image description here

As per your screenshot I can see that you are using absolute path for perl.exe. That means you have not added perl to your PATH. That seems to be the issue why IntelliJ is not finding it to execute your script.

Do

set PATH=C:\Strawberry\perl\bin;%PATH%

If that also doesn't fix the issue for you then go through the wiki page of Camelcade plugin. Author has provided step by step instructions there on how to setup this plugin.

Chankey Pathak
  • 21,187
  • 12
  • 85
  • 133
  • Is there any way I can use Cygwin instead of Strawberry Perl?? – AbhiNickz Oct 06 '16 at 06:59
  • You are also using the absolute path for perl, but you're on linux, so you can't possibly answer the question properly, as you're not using Strawberry Perl. I'm on windows, if that wasn't obvious. Where do you "do" `set PATH=C:\Strawberry\perl\bin;%PATH%`? – Menasheh Oct 06 '16 at 13:39
  • 2
    @abhinickz In intellij? Maybe you should ask that question yourself separately? – Menasheh Oct 06 '16 at 14:12
  • @Chankey, see updated answer. I did actually originally setup the perl plugin through his guide, but I didn't do the module part. I didn't understand what `DTL-fast` is, or why it is necessary. I just imported my perl code. I don't think that should make a difference to this, but let me know what you think. – Menasheh Oct 06 '16 at 14:15
  • @Menasheh Share the script and input data. – Chankey Pathak Oct 07 '16 at 05:18
  • The script is linked at the end of the post. [here](https://github.com/menasheh/mancala/blob/master/Mancala.pl) - You can run it in a normal command line first to see what inputs its supposed to take. – Menasheh Oct 07 '16 at 05:36
0

Try adding:

$| = 1;

...to the top of your script. Perl buffers stdout, adding $| = 1; causes the buffer to flush immediately and should display output from your print statements in the IntelliJ debug console.

See also:

perl $|=1; What is this?

Community
  • 1
  • 1
Kev
  • 118,037
  • 53
  • 300
  • 385