找到最后一个“}”子程序的
假设我有一个带有 Perl 代码的文件:有人知道是否有一个模块可以找到该文件中某个子例程的结束“}”。 例如:
#!/usr/bin/env perl
use warnings;
use 5.012;
routine_one( '{°^°}' );
routine_two();
sub routine_one {
my $arg = shift;
if ( $arg =~ /}\z/ ) {
say "Hello my }";
}
}
sub routine_two {
say '...' for 0 .. 10
}
该模块应该能够删除整个routine_one,或者它应该可以告诉我该例程中结束“}”的行号。
Supposed I have a file with Perl-code: does somebody know, if there is a module which could find the closing "}" of a certain subroutine in that file.
For example:
#!/usr/bin/env perl
use warnings;
use 5.012;
routine_one( '{°^°}' );
routine_two();
sub routine_one {
my $arg = shift;
if ( $arg =~ /}\z/ ) {
say "Hello my }";
}
}
sub routine_two {
say '...' for 0 .. 10
}
The module should be able to remove the whole routine_one or it should can tell me the line-number of the closing "}" from that routine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您要解析 Perl 代码,则需要使用 PPI。
You want to use PPI if you are going to be parsing Perl code.
如果您的子例程不包含任何空行(如示例中的空行),则以下内容将起作用:
The following will work in case your subroutines don't contain any blank lines, like the one in your example: