escape_Q 在我的 perl 中无法识别括号

escape_Q in my perl doesn't recognize the brackets

我在一个文件中有两行,都以 testInst_Wdata_w0_reg/Jreg_ff[0].SSS.nr

结尾
A...testInst_Wdata_w0_reg/Jreg_ff[0].SSS.nr, 

B...testInst_Wdata_w0_reg/Jreg_ff[0].SSS.nr

我想比较共同的部分。但是有“[]”,好像不能匹配。

我检查了其他线程,人们建议使用 \Q 因为 [] 在模式中有特殊含义

($ref =~ m/\Q$matching_ref_end$/))

$matching_ref_end == testInst_Wdata_w0_reg/Jreg_ff[0].SSS.nr

所以我有上面的,但它似乎不起作用。

有什么提示吗?

假设这些行确实以您声称的内容 $matching_ref_end 结尾,

/\Q$matching_ref_end$/

应该是

/\Q$matching_ref_end\E$/

因为 \Q 正在转义 $

(实际上,它应该是 /\Q$matching_ref_end\E\z/,除非你想接受尾随换行。)

但是,您显示的其中一行实际上并不像您声称的那样以内容 $matching_ref_end 结尾。一个有尾随逗号,您需要处理。