返回介绍

最佳实践 91:使用 PerlTidy 美化代码

发布于 2025-04-20 17:44:52 字数 2197 浏览 0 评论 0 收藏

在 Windows 上编写 Perl 程序时,希望能够让 Perl 代码显得更美观一些,这样不仅看起来更加清晰规范,而且易于查找出其中的拼写错误。我们推荐使用 EditPlus 这样一款简单轻便的 Perl 编辑器,下载地址是 https://www.editplus.com/ 。通过在 EditPlus 中集成 PerlTidy,可以美化 Perl 代码。配置 PerlTidy 的步骤如下。

步骤 1 下载 ActivePerl。以 Windows 764 位系统为例,需要下载对应的 64 位 Perl 安装程序,下载地址是 http://www.activestate.com/activeperl/downloads/thank-you?dl=http://downloads.activestate.com/ActivePerl/releases/5.22.1.2201/ActivePerl-5.22.1.2201-MSWin32-x64-299574.msi

步骤 2 根据提示默认安装 ActivePerl。

步骤 3 为 Perl 添加 PerlTidy 模块。添加使用的命令是:

C:\Users\xufeng02>cd c:\Perl64\bin #进入 perl.exe 安装目录

c:\Perl64\bin>perl.exe -MCPAN -e shell #进入 CPAN 安装模式

It looks like you don't have a C compiler and make utility installed.  Trying
to install dmake and the MinGW gcc compiler using the Perl Package Manager.
This may take a a few minutes...#提示安装 dmake 和 MinGW 依赖项

Downloading MinGW-4.6.3...done
Downloading dmake-4.11.20080107...done
Unpacking MinGW-4.6.3...done
Unpacking dmake-4.11.20080107...done
Generating HTML for MinGW-4.6.3...done
Generating HTML for dmake-4.11.20080107...done
Updating files in site area...done
3697 files installed

Please use the `dmake` program to run commands from a Makefile!


cpan shell -- CPAN exploration and modules installation (v2.11)
Enter 'h' for help.


cpan> install Perl::Tidy#安装 PerlTidy 模块

步骤 4 在 EditPlus 中,点击 Tools->Configure User Tools,出现图 18-2。

如图 18-2 所示,选择①User Tools,在②处输入 PerlTidy,在③处输入以下内容:

c:\Perl64\bin\perl.exe "C:\Perl64\site\bin\perltidy"

在④处输入以下内容:

"$(FilePath)" -st

在⑤处,选择 Run as Text Filter(Replace)选项,然后点击 OK 按钮保存。

步骤 5 使用 EditPlus 打开需要美化的 Perl 程序,点击 Tools->PerlTidy 即可,如图 18-3 所示。

图 18-2 PerlTidy 配置项

图 18-3 PerlTidy 的使用方法

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。