我想在地圖函數中使用Perl中遞增的索引。我的代碼是:如何在Perl映射函數中使用遞增索引?
use strict;
my $ord = "46.15,18.59,47.45,21.14";
my $c = 1;
my @a = split(",",$ord);
my $str = join("\n", map "x($c++) := $_;", @a);
print $str;
此輸出:
×(1 ++):= 46.15;
x(1 ++):= 18.59;
x(1 ++):= 47.45;
x(1 ++):= 21.14;
取而代之的是X(1 +),我想X(1),x(2)等
我怎麼能達到呢?
這是_an_答案。但是如果你想要所有的行都有'\ n',然後將它附加到'map'表達式中的每個字符串,'map ...「):= $ _; \ n」'並使用'join'''。這樣最後一個沒有'\ n'。或者'print $ str',\ n「'當然('say'爲你做了什麼) – zdim