首先,在使用引号时要非常小心,我不确定你的意思是不是
'%Filters_LN_RESS_DIR%\ARC\Options\Pega\CHF_Vega\$$(1212_GV_DATE_LDN)'
代替
"%Filters_LN_RESS_DIR%\ARC\Options\Pega\CHF_Vega\$$(1212_GV_DATE_LDN)"
这可能是一个不同的字符串。例如,如果计算,"$$" 表示变量 $PROCESS_ID。
在尝试解决谜语(不确定)并引用你的字符串之后
my $lastline =
'%Filters_LN_RESS_DIR%\ARC\Options\Pega\CHF_Vega\$$(1212_GV_DATE_LDN)'
不同的是,我会使用:
my ($w1, $w2) = $lastline =~ m{ % # the % char at the start
([^%]+) # CAPTURE everything until next %
[^(]+ # scan to the first brace
\( # hit the brace
([^)]+) # CAPTURE everything up to closing brace
}x;
print "$w1\n$w2";
提取你的话。结果:
Filters_LN_RESS_DIR
1212_GV_DATE_LDN
但是轻松替换值是什么意思。哪些价值观?
附录
现在让我们提取由'\' 分隔的“单词”。使用简单的拆分:
my @words = split /\\/, # use substr to start split after the first '\\'
substr $lastline, index($lastline,'\\');
如果您删除最后一个条目(即$$(..) 字符串),您将看到反斜杠之间的单词:
pop @words; # remove the last element '$$(..)'
print join "\n", @words; # print the other elements
结果:
ARC
Options
Pega
CHF_Vega
这是否与 grep 一起工作得更好?似乎:
my @words = grep /^[^\$%]+$/, split /\\/, $lastline;
和
print join "\n", @words;
也会导致:
ARC
Options
Pega
CHF_Vega
也许这就是你所追求的?你想用这些做什么?
问候
rbo