0

E.1.1.1在一个变量中有值,我想E111存储在不同的变量中。

$var1 = "E.1.1.1";
$var1 =~ s/\.//g;

上面的代码改变了$var1变量中的值。我想尝试如下。

$var2 = s/\.//g $var1;

建议怎么做。我是 Perl 的新手。

4

3 回答 3

2

像这样的东西应该工作:

(my $var2 = $var1) =~ s/\.//g;
于 2017-04-04T15:11:43.177 回答
2
my $var2 = $var1;
$var2 =~ s/\.//g;

或者

( my $var2 = $var1 ) =~ s/\.//g;

或者

my $var2 = $var1 =~ s/\.//gr;    # 5.14+
于 2017-04-04T15:19:04.480 回答
0

You already got universal answers using s///.

For this specific task, removing . from a string , you can also use the y (alias tr).

( my $var2 = $var1 ) =~ y/.//d;

or

my $var2 = $var1 =~ y/.//dr; #the /r needs 5.14+

More info: perlop - Quote-Like Operators

于 2017-04-04T15:39:30.570 回答