You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决macOS Ventura 13.3.1中perlcritic安装后无法运行的问题?

解决macOS上perlcritic无法运行的问题

环境信息

  • macOS Ventura 13.3.1
  • Perl版本:执行perl --version输出:
This is perl 5, version 36, subversion 0 (v5.36.0) built for darwin-thread-multi-2level
...
  • 已通过cpan Perl::Critic确认Perl::Critic为最新版本(1.150)
  • 执行perlcritic -1 list.pl时提示zsh: command not found: perlcritic
  • brew无perlcritic安装公式,仅推荐安装perltidy
  • 额外调试结果:
    • which perl输出:/opt/homebrew/bin/perl
    • perl -V:installsitebin输出:installsitebin='/opt/homebrew/Cellar/perl/5.36.0/bin';

问题原因

cpan安装的perlcritic可执行文件存放在/opt/homebrew/Cellar/perl/5.36.0/bin目录,但该目录未加入系统PATH环境变量,导致shell无法定位命令。

解决方案

方法1:直接使用全路径执行

调用perlcritic的完整路径运行:

/opt/homebrew/Cellar/perl/5.36.0/bin/perlcritic -1 list.pl

方法2:将Perl的sitebin目录加入PATH

  1. 打开zsh配置文件:
open -e ~/.zshrc
  1. 在文件末尾添加:
export PATH="/opt/homebrew/Cellar/perl/5.36.0/bin:$PATH"
  1. 保存后重新加载配置:
source ~/.zshrc

之后即可直接执行perlcritic -1 list.pl。

方法3:通过perl的-S参数执行

利用perl的-S参数自动搜索模块对应的可执行文件:

perl -S perlcritic -1 list.pl

附:测试用list.pl代码

#!/usr/bin/perl
use strict;
use warnings;

use Path::Tiny;
use autodie;

my $dir = path("/tmp"); # /tmp

my $file = $dir->child("test");

my $content = $file->slurp_utf8();

my $file_handle = $file->openr_utf8();

while( my $line = $file_handle->getline() ) {
    print $line;
}

内容的提问来源于stack exchange,提问作者baduker

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 01:32:46