#! /usr/bin/perl
use strict;
use warnings; #Always use these!
open (MYFILE, '>script2.txt');
my $world = 1;
for my $top (1 .. 100) {
for my $left (1 .. 100) {
print MYFILE "\#world$world \{
background: url(/images/1.png) 0 0 no-repeat;
float: left;
width: 1%;
height: 2%;
position: absolute;
top: $top\%;
left: $left\%;
z-index: -1;
margin-top: -10px;
margin-left: -10px;
\}
\#world$world:hover \{
background-position: 0 -20px;
cursor: pointer;
\}";
$world++;
}
}
close (MYFILE);
目前這個perl腳本生成10000項(100頂×100左右),但我怎麼可以修改它,這樣$頂部產生0,2.5,5 ... 100,而不是0,1,2,... 100和$左側產生0,1.25,2.5,...,而不是100 0,1,2,... 100Perl腳本製作變量的模式
由於
可能的重複[Perl定義了一個變量模式遵循](http://stackoverflow.com/questions/6783837/perl-defining-a-pattern-for-a-variable-to-follow) –
@Alex =>這兩個是相關的,但這顯然是一個不同的用例,它引發了一個不同的答案('map'爲細粒度迭代控制生成列表與C-style'for')。 –