【发布时间】:2009-05-01 10:12:25
【问题描述】:
我正在审查一些用 Perl 编写的 ClearCase 触发器。我注意到在一些正则表达式中,变量要么直接传递,要么用大括号括起来。
例如,我在触发器中有以下代码行:
if ($baseline !~ /^${component}_(|.*_)$phase\.\d+(|[a-z]|-\d+|${automateddigit})$/ &&
$baseline !~ /^${project_root}_$phase\.\d+(|[a-z]|-\d+|${automateddigit})$/)
$component、$phase、$automateddigit、$project_root都是变量。
为什么在正则表达式中有些传递为$variable 而有些传递为${variable}?
它来自于它们的初始化方式吗?
下面是初始化它们的代码行:
($project = $ENV{CLEARCASE_PROJECT}) =~ s/\@.*$//;
($component = $ENV{CLEARCASE_COMPONENT}) =~ s/\@.*$//;
($project_root, $phase) = ($project =~ /^(.*)_(R\d+.*)$/);
exit(0) if (! $phase);
$phase .= ".0" if ($phase =~ /^R\d+$/);
$automateddigit = '';
$istream = `cleartool desc -fmt "%[istream]p" project:$ENV{CLEARCASE_PROJECT}`;
$componentlist = `cleartool desc -fmt "%[components]Cp" stream:$ENV{CLEARCASE_STREAM}`;
$componentsnbr = split(',', $componentlist);
if ($componentsnbr > 1) {
$automateddigit .= '\\.\\d+';
}
【问题讨论】:
标签: regex perl syntax triggers clearcase