![]() |
|
XP is just a number | |
PerlMonks |
Re: perl ipcalc onelinersby monarch (Priest) |
on Jun 09, 2005 at 23:55 UTC ( [id://465359]=note: print w/replies, xml ) | Need Help?? |
Sometimes one can make these things more complicated than they are.
The first one liner I would write as the following:
What I'm doing is converting the dot notation into an integer. That way I can do bit manipulation on the address as a whole rather than trying to deal with individual bytes. To get the broadcast address should be just as easy. Although I haven't done bit inversions in Perl before..
So the whole file together looks like this:
The output is:
One lining this is left as an exercise for the reader. Update: on a more personal note I would caution against the byte-at-a-time approach because of the possible error whereby the third byte should be different to what you expect for the broadcast address.. using the netmask supplied (255.255.254.0) both the 3rd and 4th bytes are affected, not just the 4th. Update 2: Just making this more sexy, an alternative presentation of the code is as follows:
Update 3: Just letting everyone know I added readmore tags to update 2. I have to put in lots of update notices cause I was told off by a Saint yesterday for not putting update notices in every single time I make an update, no matter how small, and no matter how frequently.
In Section
Seekers of Perl Wisdom
|
|