Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.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
Perl定义一个变量要遵循的模式_Perl_Variables_Design Patterns - Fatal编程技术网

Perl定义一个变量要遵循的模式

Perl定义一个变量要遵循的模式,perl,variables,design-patterns,Perl,Variables,Design Patterns,如果您定义我的$top=0。。100你可以得到每个数字1,2,3,4…100,但是我如何定义$top只产生0,2.5,5,7.5。。。100? 谢谢 @top = map { 2.5 * $_ } 0 .. 40; 输出: $ ./test.pl $VAR1 = [ '0', '2.5', '5', '7.5', ... '95', '97.5',

如果您定义我的$top=0。。100你可以得到每个数字1,2,3,4…100,但是我如何定义$top只产生0,2.5,5,7.5。。。100? 谢谢

@top = map { 2.5 * $_ } 0 .. 40;
输出:

$ ./test.pl 
$VAR1 = [
          '0',
          '2.5',
          '5',
          '7.5',
          ...
          '95',
          '97.5',
          '100'
        ];

你是说我的@top=…,对吗?我不确定。当我运行我的perl脚本时,它现在每次打印一个不同数字的句子,所以每个句子有100个数字1…100,但是我想要50个数字为0,2.5,5。。。最多100个你不确定是什么?您显示的代码不正确,而Qtax的代码不正确?请出示您的真实代码/usr/bin/perl使用严格;使用警告;总是用这些!打开MYFILE“>script2.txt”;我的$world=1;对于我的@top=0。。100{for my@left=0..100{print MYFILE\world$world\{background:url/images/1.png 0 0无重复;float:left;宽度:1%;高度:2%;位置:绝对;top:$top\%;left:$left\%;z-index:-1;页边顶部:-10px;页边左侧:-10px;\};$world++;}关闭MYFILE;我只需要@top给出0,2.5,5的值。。100而不是0,1,2,3。。1000 .. 也许是int100/2.5?
$ ./test.pl 
$VAR1 = [
          '0',
          '2.5',
          '5',
          '7.5',
          ...
          '95',
          '97.5',
          '100'
        ];