A
Anno Siegel
eloelo said:why these code below can run only once.
For the same reason I gave in my reply to your original posting.
#!/usr/bin/perl
use NetAddr::IP;
open(D2,"IPlist");
open(D3,"IPsegment");
@line=<D3>;
$num=@line;
for($i=0;$i<$num;$i++)
{
$segment= $line[$i];
my $space = NetAddr::IP->new($segment);
The following loop reads the filehandle D2 once to eof. This happens
the first time through the outer loop. On the second and further rounds,
D2 already is at eof, so the inner loop doesn't do anything.
for my $ip (map {NetAddr::IP->new($_) } <D2>)
{
print $ip, "\n"
if $space->contains($ip);
}
}
IPlist
62.111.0.29
207.12.133.45
207.12.133.46
IPsegment
62.111.0.0/16
207.12.0.0/16
result
62.111.0.29
it means the "for"(the external one) loop run only once,why?
It runs as often as you make it, but only the first round *does*
anything.
Anno