我想要做的是這樣的:那麼Perl:我可以在變量中存儲反向引用(而不是它們的值)嗎?
my $text = "The owls are not what they seem.";
my $pattern = '(\s+)';
my $replacement = '-$1-';
$text =~ s/$pattern/$replacement/g;
$文本應該是:The- -owls- -are- -not- -what- -they- -seem。
但它當然更像是: - $ 1 - $ 1 - $ - 1 - $ - 1 - $ - 1 - $ - 1 - scree。
我試過各種反向引用($ 1,\ 1,\ g {1},\ g1),他們都沒有 的工作。/e修飾符也不起作用。這可能嗎?
目的是改變物體內的一些文字,像這樣一行: $對象 - >替換(「()OO」,「$ 1AR」)
任何其他的想法這到底是怎麼做了什麼?
非常感謝。
qr /(\ s +)/比'(\ s +)'更好' – 2009-12-15 18:44:09