为什么#字符被视为'字' Perl中的角色?或者我误解了这段代码应该如何工作?
#!/usr/bin/perl
my $filename = "Something_with_#_sign.jpg";
$filename =~ s/ # substitute...
[^ # characters which are NOT:
\w # "word" characters
] # end of character classes
/_/xg; # ...with an underscore
print "$filename\n";
收率:
Something_with_#_sign.jpg
我原本预计#符号会被_(下划线)替换。
答案 0 :(得分:10)
/x
不会修改字符类(或\x20
或s{3,4}
等)的语法,所以
[^ # characters which are NOT:
\w # "word" characters
] # end of character classes
是一种奇怪的写作方式
[^ "#:NOTacdefhilnorst\n\w]