找到运算符期望语法错误的裸字

Din*_*avi 0 perl

我是perl的新手.无论如何,我试图调试自己.但我无法指出它

语法错误是

Bareword found where operator expected at D:\DevelopmentLab\softwares\sc-master\sc.pl line 468, near "s%/%_%gr"
syntax error at D:\DevelopmentLab\softwares\sc-master\sc.pl line 468, near "s%/%_%gr"
Execution of D:\DevelopmentLab\softwares\sc-master\sc.pl aborted due to compilation errors.
Run Code Online (Sandbox Code Playgroud)

代码是

sub getBackupFileName {
my ($containerName, $volume) = @_;
my $backupFileName = $volume =~ s%/%_%gr;
return "${containerName}_${backupFileName}.tar";
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将受到高度赞赏..

Dav*_*oss 9

/r期权s/.../.../在Perl 5.14加入(2011年).如果您使用的是早期版本,则代码将无法使用.我没有可用于测试的早期版本,因此我无法确定它是否会提供您看到的错误消息.

在早期版本的Perl上使用它的最简单的解决方法是这样的:

sub getBackupFileName {
  my ($containerName, $volume) = @_;

  (my $backupFileName = $volume) =~ s%/%_%g;

  return "${containerName}_${backupFileName}.tar";
}
Run Code Online (Sandbox Code Playgroud)