我需要一些关于 Perl 中的 map 函数的帮助,它似乎对我的数组进行了裁剪。
#!/usr/bin/perl
use Math::Trig;
my @Degre = map {rand(360)} (1..2000);
my @step= map {rand(.5)} (1..2000);
my @aa = map {rand(2000)} (1..2000);
my @bb = map {rand(2000)} (1..2000);
for ($i = 0; $i <=100; $i++)
{
my @xx = map {$aa[$_]*(cos($Degre[$_])*(pi/180))}(1..2000);
my @yy = map {$bb[$_]*(cos($Degre[$_])*(pi/180))}(1..2000);
@Degre = map {@Degre[$_] + @step[$_]} (1..2000);
print "@bb[1] @aa[1] @Degre[1] @step[1] \n";
}
现在这个输出给出了
1146.56471948439 1909.33326800968 329.443529905881 0.117635819122725
1146.56471948439 1909.33326800968 343.482356802257 0.117635819122725
1146.56471948439 1909.33326800968 164.500200570578 0.117635819122725
1146.56471948439 1909.33326800968 252.734665366625 0.117635819122725
1146.56471948439 1909.33326800968 274.983382178209 0.117635819122725
1146.56471948439 1909.33326800968 324.609187610893 0.117635819122725
1146.56471948439 1909.33326800968 261.96207333817 0.117635819122725
1146.56471948439 1909.33326800968 279.442105351764 0.117635819122725
第三列是度数,我不明白为什么当我预计它会以 0.117635..... 步长增加时它似乎随机跳跃?
干杯
更新
为了确认我正在尝试让地图声明执行以下操作
for ($x = 0; $x <=2000; $x++)
{
$degre[$x] = $degre[$x] + $step[$i]
}
将代码更改为
for ($i = 0; $i <=100; $i++)
{
my @xx = map {$aa[$_]*(cos($Degre[$_])*(pi/180))}(1..2000);
my @yy = map {$bb[$_]*(cos($Degre[$_])*(pi/180))}(1..2000);
#@Degre = map {$Degre[$_] + $step[$_]} (1..2000);
for ($x = 0; $x <=2000; $x++)
{
$Degre[$x] = $Degre[$x] + $step[$x];
}
给出以下输出
738.346205775827 646.171091419262 395.07480695473 0.484472140779317
738.346205775827 646.171091419262 395.559279095509 0.484472140779317
738.346205775827 646.171091419262 396.043751236288 0.484472140779317
738.346205775827 646.171091419262 396.528223377068 0.484472140779317
738.346205775827 646.171091419262 397.012695517847 0.484472140779317
738.346205775827 646.171091419262 397.497167658626 0.484472140779317
738.346205775827 646.171091419262 397.981639799406 0.484472140779317
738.346205775827 646.171091419262 398.466111940185 0.484472140779317
正如您所看到的,度数列现在每次考虑循环时都会按步长值正确递增。那么为什么地图不做同样的事情。