【发布时间】:2015-06-07 00:19:45
【问题描述】:
我有一个具有多种功能的代码
void fun_one()
{
tempa=10;
tempb=10;
}
void fun_two()
{
tempc=12;
tempd=13;
}
如果我输入变量名,我想要提取函数名的 perl 代码;
假设我搜索“tempa”,它应该将“fun_one”提取到一个变量中;
假设我搜索“tempd”,它应该将“fun_two”提取到一个变量中;
我已经提取了行号
open my $code, '<', 'code.txt' ;
my $keyword = "tempa";
my $regex = qr|\b($keyword)\b|;
while ($code>)
{
while (/$regex/g)
{
print "$.\n";
}
}
输出:3 我需要一些逻辑来提取函数名称。
提前致谢
【问题讨论】:
-
打开我的 $code, ') { while (/$regex/g) { print "$.\n"; } }
-
请使用编辑功能添加您的问题。