in reply to generate range of IP address

*sigh*. Fish.

use constant NUM_TO_MAKE => 2000; my @addrs; my $made = 0; OUTER: for my $i ( 1 .. 254 ) { for my $j ( 1 .. 254 ) { for my $k ( 1 .. 254 ) { for my $l ( 1 .. 254 ) { push @addrs, "$i.$j.$k.$l"; last OUTER if ++$made >= NUM_TO_MAKE; } } } }

And yes, the 254s are intentional. I don't think you want to be generating probable broadcast addresses; if you do, season to taste.

Replies are listed 'Best First'.
Re^2: generate range of IP address
by cjaar (Initiate) on May 21, 2007 at 14:09 UTC
    hmm thx, just to understand ur code OUTER: is to comeout of all the for loops ? i tried something like "last if() " i missed the made also, to keep the how many i made :(

      OUTER is a label, as shown in the documentation for last and in perlsyn (see the section "Compound Statements").