基于SO回答“my ($export = $doc) =~ s{.odt}{.pdf};”为什么这个Perl脚本会产生编译错误?
$ cat so.pl
#!/usr/bin/perl
my $doc ="x.odt";
my ($export = $doc) =~ s{\.odt}{.pdf};
$ ./so.pl
Can't declare scalar assignment in "my" at ./so.pl line 3, near ") =~"
Execution of ./so.pl aborted due to compilation errors.
答案 0 :(得分:4)
将 my 放在括号内...
(my $export = $doc) =~ s{\.odt}{.pdf};