Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by merlyn (Sage)
on Mar 31, 2005 at 17:19 UTC ( [id://443898]=note: print w/replies, xml ) Need Help??


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

my $octet = join ",", 1..254; my @result = glob "192.168.{$octet}.{$octet}";

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re^2: Adding an Entire Class B IP Range to an Array
by johnnywang (Priest) on Mar 31, 2005 at 17:58 UTC
    Can someone explain this, please? it works, but I don't understand it.

      By reading the docs on glob, we note that this is now implemented in terms of File::Glob. Check that documentation out for File::Glob, and look for GLOB_BRACE.

      Here it happens that knowing how csh works is advantageous when coding perl.

Re^2: Adding an Entire Class B IP Range to an Array
by kelan (Deacon) on Mar 31, 2005 at 21:08 UTC

    I thought this might progress the braced expressions together (giving '192.168.1.1', '192.168.2.2', '192.168.3.3', etc.) so I wanted to test it. But when I did, it didn't even do that. Instead it gives:

    192.168.1.
    192.168.2.
    192.168.3.
    192.168.4.
    192.168.5.
    192.168.6.
    192.168.7.
    192.168.8.
    192.168.9.
    192.168.10.
    192.168.11.
    192.168.12.
    192.168.13.
    192.168.14.
    192.168.15.
    192.168.16.
    192.168.17.
    192.168.18.
    192.168.19.
    192.168.20.
    ...
    
    Is there a limit to glob expansion? It works as expected if I change 1..254 to 1..6, for example.

Re^2: Adding an Entire Class B IP Range to an Array
by Dru (Hermit) on Mar 31, 2005 at 17:24 UTC
    Beautiful. I might have to use this instead.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-03-28 12:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found