在这里组合文档,替换和死亡时消除中间变量

R2B*_*2B2 0 perl

$msg在这个例子中是否可以消除中间变量的使用?

($msg = <<'END_MSG') =~ s/\n//gm;
My super error message
Which happens to span over multiple lines
But that I want to print without newlines.
END_MSG
die $msg;
Run Code Online (Sandbox Code Playgroud)

如果我不需要删除换行符,我可以直接执行,die <<'END_MSG'; ...但我还没有找到将这两种方法结合起来的方法.

Сух*_*й27 5

使用perl 5.14或更新版本,你可以,

die <<'END_MSG'
My super error message
Which happens to span over multiple lines
But that I want to print without newlines.
END_MSG
=~ s/\n//gr;
Run Code Online (Sandbox Code Playgroud)

编辑:或

die <<'END_MSG' =~ s/\n//gr
..
END_MSG
Run Code Online (Sandbox Code Playgroud)

  • 或者`die <<'END_MSG'= ~s/\n // gr; ......`如果你不想在底部隐藏`///`. (2认同)