in reply to Subnet Overlap
Hello, I've reviewed your code and I have a number of comments to make. First things first: I hate to break it to you, but a lot of the code could be replaced by a couple of lines of code from a CPAN module, like Net::CIDR or NetAddr::Ip. I'd also wager a beer that there's a bug or two present in your code. That is not to mean you're not a good programmer, but IP address arithmetic is notoriously hard to get right. By using either of these modules, you're getting code that has been thoroughly exercised by people in many contexts, over many years.
Apart from the design design to clear the screen when the program is run (something that many people find irritating), the execution of the program 'clear' only happens to work because you're not using strict. Thus, the perl interpreter first tries to see if clear is an internal routine, and after having given up, it ends up interpreting the bare word as a string. So it works, but it's a dodgy practice.
One of the reasons I think that the code may have bugs is because you are using string comparisons ($match gt 1) rather than numeric comparisons ($match > 1). Comparing against one may be safe, but remember that 9 > 10 evaluates to true. Say what you mean, to be certain.
Elsewhere in the code, a comment says:
Due to a bug in Perl, after the split, the new variables need to have an mathmatical operation performed in order to make them numeric variables rather than string variables.
This is quite untrue and more indicative of your own misunderstanding of how Perl deals with strings. If you put a variable in an arithmetic expression, Perl will treat it as a number. Thus "2" + "2" equals 4, but "2" . "2" equals "22". split will return just what you want. Numbers or strings, it's your call.
Briefly in passing, consider using the 3-arg form of open, don't call functions with ampersand (&func;) and do use strict.
Also, rather than dealing with the mechanics of opening and closing files, you can ditch a lot of code by just reading from STDIN and writing to STDOUT, and deal with what file is to be read, and to what file the results should be written, from the shell. Less code, less things to go wrong.
I must apologise if this all comes out sounding a bit harsh, that is not my intent, but I don't have the time to be more diplomatic. We are all here to learn, and if you learn from this post, then we're one step ahead.
Keep perling!
• another intruder with the mooring in the heart of the Perl
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Subnet Overlap
by ikegami (Patriarch) on Aug 21, 2007 at 20:22 UTC | |
by bfarley (Initiate) on Aug 22, 2007 at 03:07 UTC | |
|
Re^2: Subnet Overlap
by bfarley (Initiate) on Aug 22, 2007 at 03:01 UTC |