【发布时间】:2015-10-26 09:37:34
【问题描述】:
我试图在 Perl 中字符串的每个分号后插入一个空格。
#!/usr/bin/perl
use strict; use warnings;
my $string = "1234;5678;232;5774;9784";
$string =~ s/;/"; "/g;
my $matched = $1;
print $matched . "\n";
但它不起作用。我的字符串是1234;5678;232;5774;9784。我想打印1234; 5678; 232; 5774; 9784。谢谢
【问题讨论】:
-
所以它只是再次打印出原始字符串?
-
错误消息显示
Use of uninitialized value $matched in concatenation (.) or string at...。正则表达式与字符串中的任何内容都不匹配。 -
将
print $string, "\n";添加到末尾,您将看到匹配已发生。没有发生的是捕获。