Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays perl数组元素减法_Arrays_Perl - Fatal编程技术网

Arrays perl数组元素减法

Arrays perl数组元素减法,arrays,perl,Arrays,Perl,我有一个如下的数组 --------------------------------- 1 2 3 4 5 411625-411626-411629-411629-411630 1 3 0 1 数组=(411625411626411629411630) 我想得到相邻元素数组中的增量,并输出如下 --------------------------------- 1 2 3 4

我有一个如下的数组

--------------------------------- 1 2 3 4 5 411625-411626-411629-411629-411630 1 3 0 1 数组=(411625411626411629411630)

我想得到相邻元素数组中的增量,并输出如下

--------------------------------- 1 2 3 4 5 411625-411626-411629-411629-411630 1 3 0 1 --------------------------------- 1 2 3 4 5 411625-411626-411629-411629-411630 1 3 0 1
这应该让你开始:

#!/usr/bin/perl
use warnings;
use strict;
use feature qw{ say };

my @array=(411625, 411626, 411629, 411629, 411630);

say join "\t", 1 .. @array;
say join '-', @array;
say join "\t", map $array[$_] - $array[$_ - 1], 1 .. $#array;

你的输入和输出是不同的?谢谢你指出了这一点,我已经解决了