Fellow Monks,
Two questions:
1.) I have a bunch of ip addresses saved to a hash, with the ip being the hash key. I would like to know those networks (Class C's) that have the last octet in a sequential order from 0.255. For example:
192.168.1.0
192.168.1.1
192.168.1.2
.
.
192.168.1.255
I honestly can not think of an easy way to do this. The only thing I can think of is have 255 if statements and if they all match, I have what I am looking for. I know this is just asinine and I would rather jump off the nearest bridge.
2.) Since I am trying to expand my limited knowledge of map and grep functions, I would be most gratefull if someone could post a solution using either or both of those, which from what I understand of them is probably my best choice.
The closes I can get with grep is the following:
my @segments = grep {/^(\d{1,3}\.\d{1,3}\.\d{1,3})/} keys %hashIPs;
Although this saves the entire ip, rather then the first three octets, which is what I am after. Is it possible to save $1 with grep?
Thanks,
Dru
Perl, the Leatherman of Programming languages. -
qazwart
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.