Sublime Forum

Possible to run Perl in Sublime Text?

#1

Hi,

Can anyone advise please on whether it’s possible to run Perl scripts within Sublime Text and if so, how do I do that? Thanks for any advice.

Best wishes,

John

0 Likes

#2

Basically you have 2 options

Option 1: Sublime Build System

You can create a Packages/User/Perl.sublime-build file with the following content.

{
	"shell_cmd": "perl \"${file}\"",
	"selector": "source.perl",
	"variants":
	[
		{
			"name": "Syntax Check",
			"shell_cmd": "perl -c \"${file}\"",
			"file_regex": "^.*? at (.*?) line ([0-9]+)",
		}
	]
}

This enables you to run unattended scripts via F7 or Ctr+B.

Option 2: Terminus

You can install Terminus Package.

  1. You can open an interactive shell session with Perl as the interpreter.
  2. You can configure Terminus as build system. This would basically work like option 1 but enable you to interactively interact with the script.
0 Likes

#3

Hi,

Thanks for your reply. To be honest, this is all a bit over my head and I can foresee trouble ahead if I try to do this. I had hoped there would be a simple (ish) fix, but I have no idea how to do any of the above. Thanks anyway for your advice.

Regards,

John

0 Likes

#4

This is a re-telling of DeathAxe’s suggestion:

  1. Go to the top menu for “Preferences > Browse Packages…”. This will load a file browser.
  2. In the User folder, make a new text file named Perl.sublime-build.
  3. Paste in the content from the first response and save.
  4. Open your Perl file.
  5. Ctrl+B

If you’re on Mac, the menu in Step 1 is under “Sublime Text,” and in Step 5, use Cmd+B

0 Likes

#5

You can also select Tools > Build System > New Build System... from the menu. That creates a stub file for you that has the appropriate syntax set automatically and sets up the buffer to save as the right file type directly into your User package when you save.

1 Like

#6

Hi Michael,

Thank you for your advice - I’ll give that a try (probably tomorrow or Monday) and see if I can get it to work. Will post an update of how it goes.

One quick query - DeathAxe mentioned that this solution would allow ‘unattended’ scripts to run. I’m not clear about the terminology, but I suspect it means that I would not be able to interact with the script, as in typing in a response to a query. Is that right? If so, is there any way that the code could be modified so as to allow for this?

Thanks again for your advice.

Regards,

John

0 Likes

#7

Hi Odat,

Thanks for your post. That’s given me another avenue to explore in order to get this to work. Much appreciated.

Regards,

John

0 Likes

#8

You suspect correctly, and no, there is not a way that I am aware of. Instead, install the Terminus package (DeathAxe’s “Option 2”), and make a build system for it. This is my untested, seat-of-the-pants guess at what that build system looks like, combining DeathAxe’s post with the Terminus suggestion for a project-specific build system:

{
	"shell_cmd": "perl \"${file}\"",
	"selector": "source.perl",
	"target": "terminus_open",
        "working_dir": "$folder",
        "auto_close": false
}
1 Like

#9

Hi Michael,

I tried your first suggestion (creating new text file 'Perl.sublime-build) and I’m happy to say that has worked perfectly. I’m really pleased - thank you for that.

As we suspected though, it doesn’t allow me to run interactive scripts. Although this shouldn’t be a huge problem, I’d quite like to have a go at DeathAxe’s ‘Option 2’. I’ve installed the Terminus package as required, but am unclear about how to go about making a build system for it. Can you advise on this at all? Where would I paste the text you mentioned in your last post?

If you could even just point me to some relevant reading material, that would be great.

Thanks again for your help.

Regards,

John

0 Likes

#10

Replace the Perl.sublime-build you just made with the snippet from my post. I’m sorry, but I can’t guarantee that it works. (I don’t actually use Terminus.)

If you have trouble, you could try digging through the samples and documentation on the Terminus package’s GitHub. If you still can’t work it out, you could ping the author in this thread by including “@randy3k” in a reply. Please try to get it working on your own before sending Randy a ping.

Good luck!

0 Likes

#11

I’ll give that a try - thanks.

Best wishes,

John

0 Likes