我可以使用 Xcode 作为 Perl 脚本的 IDE 吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24092254/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:01:55  来源:igfitidea点击:

Can I use Xcode as an IDE for Perl scripts?

xcodeperl

提问by Steve HHH

I am using OS X 10.9 (Mavericks) and need to work on a Perl project. I enjoy using TextMate, Atom, and BBEdit, but would like to try using Xcode instead, as it has good integration with git, a clean look, and I am already intimately familiar with the UI and syntax highlighting colour scheme.

我正在使用 OS X 10.9 (Mavericks) 并且需要处理 Perl 项目。我喜欢使用 TextMate、Atom 和 BBEdit,但想尝试使用 Xcode,因为它与 git 有很好的集成、干净的外观,而且我已经非常熟悉 UI 和语法高亮配色方案。

Is it possible to use Xcode as an IDE to develop and run Perl scripts, in a way that puts it on par, or ahead of, existing text editors?

是否可以使用 Xcode 作为 IDE 来开发和运行 Perl 脚本,使其与现有文本编辑器相提并论或领先于现有文本编辑器?



Update

更新

I used Xcode 5 as an IDE for Perl for more than a month, and found it an excellent alternative to regular text editors like Atom and TextMate. However, like pure text editors, Xcode lacks support for debugging in Perl. I have since discovered Komodo IDE, a really nice IDE for Perl (and similar languages) that supports graphical Perl debugging, plus remote Perl debugging. I have since switched from using Xcode for Perl development to using Komodo IDE.

我使用 Xcode 5 作为 Perl 的 IDE 一个多月,发现它是 Atom 和 TextMate 等常规文本编辑器的绝佳替代品。但是,与纯文本编辑器一样,Xcode 不支持在 Perl 中进行调试。从那以后,我发现了Komodo IDE,这是一个非常好的 Perl(和类似语言)IDE,支持图形 Perl 调试,以及远程 Perl 调试。从那以后,我从使用 Xcode 进行 Perl 开发切换到使用 Komodo IDE。

回答by Steve HHH

After some experimentation, it seems that Xcode makes for a fairly decent environment for developing Perl. Here is a screenshot of Xcode showing some Perl, project navigator, Git integration, and command-line output from a Perl script, as run by Xcode.

经过一些实验,Xcode 似乎为开发 Perl 提供了一个相当不错的环境。这是 Xcode 的屏幕截图,显示了一些 Perl、项目导航器、Git 集成和 Perl 脚本的命令行输出,由 Xcode 运行。

enter image description here

在此处输入图片说明

Xcode 5's built-in syntax highlighting works fine with Perl (.pland .pm) files, right out of the box. But to use Xcode to write Perl more efficiently, you'll want to set up a new Xcode project:

Xcode 5 的内置语法高亮显示适用于 Perl(.pl.pm)文件,开箱即用。但是要使用 Xcode 更有效地编写 Perl,您需要设置一个新的 Xcode 项目:

  1. Create a new Xcode workspace (File> New> Workspace) and select the folder you want to use for the Perl project.

  2. Enable the Xcode navigator, so you can see the files in your project (View> Navigators> Show Navigators). Notice that Xcode does not show you a list of files in the workspace folder by default. If you're reading this, you're probably already an Xcode user, already knew that.

  3. Manually add any files, or folders (groups, in Xcode parlance), that you want to see in the project (right-click on the Project Navigator pane and select Add files to "Project Name). Create groups to mirror your folder structure and add any files in subfolders to the groups. This can be a bit of work, depending on the size of your Perl project, but once you're set up it should not change much.

  4. Click on your files in the Project Navigator to view the code. If you are using a Git or Subversion, Xcode will generate diffs as normal in the Xcode version editor.

  5. To get your Perl script running when you hit Cmd-R:

    • Create a new scheme (Product> Scheme> New Scheme), configure Targetto Noneand assign a name like Run Perl.

    • After creating the scheme, hit Edit Scheme.

    • In the Run perlscheme, set the Executableto /usr/bin/perl(select Otherthen press Shift-Cmd-G, enter /usr/bin/perl, and press Choose).

    • Go to the Argumentstab and ensure that your main script is the first argument. Add more arguments and environment variables as necessary.

    • Go to the Optionstab and set Use custom working directoryto your project folder. Deselect XPC services and any other options related to iOS or OS X development.

  1. 创建一个新的 Xcode 工作区(File> New> Workspace)并选择要用于 Perl 项目的文件夹。

  2. 启用 Xcode 导航器,以便您可以查看项目中的文件(View> Navigators> Show Navigators)。请注意,默认情况下,Xcode 不会向您显示工作区文件夹中的文件列表。如果您正在阅读本文,您可能已经是 Xcode 用户,并且已经知道这一点。

  3. 手动添加您想要在项目中看到的任何文件或文件夹(在 Xcode 中为)(右键单击项目导航器窗格并选择将文件添加到“项目名称”)。创建组以镜像您的文件夹结构和将子文件夹中的任何文件添加到组中。这可能需要一些工作,具体取决于您的 Perl 项目的大小,但是一旦设置好,它就不应该有太大变化。

  4. 在项目导航器中单击您的文件以查看代码。如果您使用的是 Git 或 Subversion,Xcode 将在 Xcode 版本编辑器中正常生成差异。

  5. 要在您点击时运行您的 Perl 脚本Cmd-R

    • 创建一个新方案(Product> Scheme> New Scheme),将Target配置为None并分配一个名称,如Run Perl

    • 创建方案后,点击Edit Scheme

    • Run perl方案中,将Executable设置为/usr/bin/perl(选择其他,然后按Shift- Cmd- G,输入/usr/bin/perl,然后按选择)。

    • 转到Arguments选项卡并确保您的主脚本是第一个参数。根据需要添加更多参数和环境变量。

    • 转到选项选项卡并将使用自定义工作目录设置为您的项目文件夹。取消选择 XPC 服务以及与 iOS 或 OS X 开发相关的任何其他选项。

Press OKand when you press Cmd-Rin Xcode, Xcode will call Perl, run your script, and show you the output.

OK,当您Cmd-R在 Xcode 中按时,Xcode 将调用 Perl,运行您的脚本,并向您显示输出。

To get Perl snippets and templates in Xcode, see How to create project templates in Xcode 4.

要在 Xcode 中获取 Perl 片段和模板,请参阅如何在 Xcode 4 中创建项目模板

Extra tips:

额外提示:

  • If you are working with files that have extensions for an language that Xcode does not recognise, such as .sql files, you may be able to use the generic syntax highlighting. Go to Editor> Syntax Highlighting> Generic.
  • 如果您正在处理具有 Xcode 无法识别的语言扩展名的文件,例如 .sql 文件,您可以使用通用语法突出显示。转到Editor> Syntax Highlighting> Generic