Can the following Perl code be simplified into one statement:
可以将以下Perl代码简化为一个语句:
my $a = 'hello'; my $b = $a; $b =~ s/o//;
我的$ a ='你好';我的$ b = $ a; $ b = ~s / o //;
I am looking for something like:
我正在寻找类似的东西:
$b = $a =~ s/o//;
$ b = $ a = ~s / o //;
(although that does not produce what I want; $b becomes "1" or "true")
(虽然这不会产生我想要的东西; $ b变成“1”或“真”)
2 个解决方案
#1
6
Close; you need some extra parentheses, because =
is lower precedence than most operators.
关;你需要一些额外的括号,因为=的优先级低于大多数运算符。
($b = $a) =~ s/o//;
#2
1
Try this :
尝试这个 :
( $b = $a ) =~ s/o//;
#1
6
Close; you need some extra parentheses, because =
is lower precedence than most operators.
关;你需要一些额外的括号,因为=的优先级低于大多数运算符。
($b = $a) =~ s/o//;
#2
1
Try this :
尝试这个 :
( $b = $a ) =~ s/o//;