我有很多文件需要更改一行。
这是代码:
GetOptions ('full' => \$full,
'dbno=s' => \$dbno,
'since=s' => \$since,
'printSQL' => \$printSQL,
'nwisDB=s' => \$nwisDBOption);
# Find the NWISDB to be extracted
if ($nwisDBOption eq '') {
$nwisdb = &WSCExtractor::getNwisdb;
} else {
$nwisdb = uc($nwisDBOption);
}
这是我想要的:
GetOptions ('full' => \$full,
'dbno=s' => \$dbno,
'since=s' => \$since,
'printSQL' => \$printSQL,
'nwisDB=s' => \$nwisDBOption) || &WSCExtractor::usage();
# Find the NWISDB to be extracted
if ($nwisDBOption eq '') {
$nwisdb = &WSCExtractor::getNwisdb;
} else {
$nwisdb = uc($nwisDBOption);
}
这是我正在使用的 perl 命令:
perl -pi -e "s/\\\$nwisDBOption\);/\\\$nwisDBOption\) || \&WSCExtractor::usage\(\);/" extractor-template
结果如下:
GetOptions ('full' => \$full,
'dbno=s' => \$dbno,
'since=s' => \$since,
'printSQL' => \$printSQL,
'nwisDB=s' => \$nwisDBOption) || &WSCExtractor::usage();
# Find the NWISDB to be extracted
if ($nwisDBOption eq '') {
$nwisdb = &WSCExtractor::getNwisdb;
} else {
$nwisdb = uc($nwisDBOption) || &WSCExtractor::usage();
}
它匹配 $nwisDBOption 的第二个实例,即使它前面没有 \。我尝试在前面添加更多 \ 以防 perl 吃掉它们。当时不匹配。谢谢。