我正在审查一些用 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+';
}