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


In reply to Re: Subnet Overlap by grinder
in thread Subnet Overlap by bfarley

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.