Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging Perl with Visual Studio Code

I have just started with Perl today and installed ActivePerl 5.24.1 and everything went well. I was able to create my test program testPerl.pl with simple a print command and run it through console.

Now I wanted to use Visual Studio Code to run my Perl script, and so I opened the project folder [testPerl.pl location] with Visual Studio Code and tried to debug the code. I have installed the Perl-Debug extension in the editor and when I hit F5, Visual Studio Code asked me to Select Environment and I chose the Perl Debug option, which actually created the launch.json file for me with the below contents.

{
    "version": "0.0.2",
    "configurations": [
        {
            "type": "perl",
            "request": "launch",
            "exec": "perl",
            "name": "Perl-Debug",
            "root": "${workspaceRoot}/",
            "program": "${workspaceRoot}/${command.AskForProgramName}",
            "inc": [],
            "stopOnEntry": true
        }
    ]
}

I have kept default values as it, and when I hit F5 again, it asked me for a command with default value test.pl. It is because of ${command.AskForProgramName}, I assume. I entered my file name testPerl.pl in the command, but then nothing happens. It starts and ends without any print in console.

How can I actually configure this launch.json file or is there another way I need to do this?

like image 624
Guruprasad J Rao Avatar asked Jan 19 '17 05:01

Guruprasad J Rao


People also ask

Does Visual Studio code support Perl?

Install Visual Studio Code To write Perl code, you can use any plain text editor e.g., notepad, notepad++, or any text editors of your choice. To make it easier to write Perl code, you need to have a good code editor with syntax highlighting and other features. One of these editors is Visual Studio Code which is free.

Does Perl have a debugger?

In Perl, the debugger is not a separate program the way it usually is in the typical compiled environment. Instead, the -d flag tells the compiler to insert source information into the parse trees it's about to hand off to the interpreter.


2 Answers

I ran Visual Studio Code on a Mac and changed

"program": "${workspaceRoot}/${command.AskForProgramName}"

to

"program": "${file}"

to get the current file to debug.

like image 165
seifel Avatar answered Oct 07 '22 11:10

seifel


I tried with a newer version of the plugin: Perl Debug version 0.2.0.

This works out of the box. The proposed configuration looks as follows:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "perl",
            "request": "launch",
            "name": "Perl-Debug local",
            "program": "${workspaceFolder}/${relativeFile}",
            "exec": "perl",
            "execArgs": [],
            "root": "${workspaceRoot}/",
            "inc": [],
            "args": [],
            "env": {},
            "stopOnEntry": true
        },
        {
            "type": "perl",
            "request": "launch",
            "name": "Perl-Debug remote",
            "program": "${workspaceFolder}/${relativeFile}",
            "root": "${workspaceRoot}/",
            "stopOnEntry": true,
            "port": 5000
        }
    ]
}

Do note I tried this out on a Mac, with Visual Studio Code version 1.24.0.

like image 43
jonasbn Avatar answered Oct 07 '22 11:10

jonasbn