#! /usr/bin/perl
use strict;
use warnings; #Always use these!
my @no = (1 .. 100);
foreach(@no) {
print "\#world" . $_ . " \{
background: url(/images/1.png) 0 0 no-repeat;
float: left;
width: 1%;
height: 2%;
position: absolute;
top: " . $_ . "\%;
left: " . $_ . "\%;
z-index: -1;
margin-top: -10px;
margin-left: -10px;
\}
\#world" . $_ . ":hover \{
background-position: 0 -20px;
cursor: pointer;
\}";
}
目前这个perl脚本输出#world1, top: 1%; left: 1%;
,其中百分比相同。如何修改脚本以将world(1 through to 100) top: 1%; left: (1% through to 100%)%; world(101 through to 201) top: 2%; left: (1% through to 100%)%;
输出到world(19001 through to 20000) top: 100%; left: (1% through to 100%)%;
答案 0 :(得分:1)
这会为每个上/左值对添加$world
的唯一编号。
my $world = 1;
for my $top (1 .. 100) {
for my $left (1 .. 100) {
# print here... world$world top = $top, left = $left...
$world++;
}
}