The code below returns me nothing.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top