in reply to Breaking up a list of IP addresses for Snort
if ($w eq $fred[-1])
However, even that looks a bit messy. How aboutfor ( my $chunk = 0; $chunk < @fred; $chunk += 20 ) { print "var $varname $chunk [\n"; print "$fred[$chunk]"; for my $ofs ( 1 .. 19 ) { print ",$fred[$chunk+$ofs]"; } print "]\n"; }
This deviates from your model by having the chunks labeled 0, 20, 40..., rather than 0, 1, 2... If that part is important, you could fix it by doing (e.g.)for ( my $chunk = 0; $chunk < @fred; $chunk += 20 ) { local $" = ','; print "var $varname $chunk [@{[ map { $fred[ $chunk+$_] || () } 0 +.. 19 ]}]\n"; }
print "var $varname ", $chunk/20, " . . .
|
|---|