How to get perl script to generate every combination of two variables
#! /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;
\}";
}
currently this perl script outputs #world1, top: 1%; left: 1%;
where the percentages are the same. How can i modify the script to output world(1 through to 100) top: 1%; left: (1% through to 100%)%; world(101 through to 201) top: 2%; left: (1% through to 100%)%;
up to world(19001 through to 20000) top: 100%; left: (1% through to 100%)%;
This will add a unique number for $world
for every top/left value pair.
my $world = 1;
for my $top (1 .. 100) {
for my $left (1 .. 100) {
# print here... world$world top = $top, left = $left...
$world++;
}
}
精彩评论