Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Adding an Entire Class B IP Range to an Array

by Jaap (Curate)
on Mar 31, 2005 at 16:59 UTC ( [id://443889]=note: print w/replies, xml ) Need Help??


in reply to Adding an Entire Class B IP Range to an Array

You can use map from within map which would be quite ugly for more than 2 levels an quite hard for n levels where n is determined at runtime.
my @hosts = map {my $i = $_; map {"192.168.$i.$_"} 1 .. 254} 1 .. 254;

Replies are listed 'Best First'.
Re^2: Adding an Entire Class B IP Range to an Array
by Roy Johnson (Monsignor) on Mar 31, 2005 at 18:24 UTC
    [nesting maps] would be quite hard for n levels where n is determined at runtime
    That's what Algorithm::Loops 'NestedLoops' is for. And (because I need to practice using it) the solution corresponding to yours would be
    use Algorithm::Loops 'NestedLoops'; my @hosts = NestedLoops([([1..254])x2], sub { "192.168.$_[0].$_[1]" }) +;

    Caution: Contents may have been coded under pressure.
Re^2: Adding an Entire Class B IP Range to an Array
by ikegami (Patriarch) on Mar 31, 2005 at 17:23 UTC
    The outer 1..254 (3rd octet) should be 0..255 if you don't wanna skip 510 valid addresses.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://443889]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-25 22:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found