7
在Perl中,我希望能夠做到這一點:perl大小寫敏感開關爲變量?
$switches = "is";
$regexp = "\\d";
if ($string =~ m/$regexp/$switches) {
do something...
}
換句話說,我怎樣才能使「$開關」可選在運行時? (用戶可以從各種的搜索選項中進行選擇)
在Perl中,我希望能夠做到這一點:perl大小寫敏感開關爲變量?
$switches = "is";
$regexp = "\\d";
if ($string =~ m/$regexp/$switches) {
do something...
}
換句話說,我怎樣才能使「$開關」可選在運行時? (用戶可以從各種的搜索選項中進行選擇)
if ($string =~ /(?$flags:$pattern)/) {
...
}
注:如果$pattern
是編譯模式(即由qr//
生產),因爲它是通過標誌這將無法正常工作,而不是字符串到qr//
影響編制與qr//
的模式。您必須將標誌傳遞給qr//
而不是m//
。
謝謝,@ikegami。非常明確的答案。 – sploiber
什麼樣的開關?你的意思是命令行參數? './foo.pl arg1 -arg2 = foo'? –
@Marc B,匹配運算符標誌 – ikegami