First a "critical" error: you use an OS function "open" without checking for any error state. You should always, at minimal, use " or die $!" to print out some useful error message on these types of calls.

I think the first thing to concern yourself with is style, assuming that the code above is not the result of errors introduced during cut and pasting. There's no indenting, which is very helpful in trying to identify loops. Other points where I see that it could be improved is adding more carriage returns to help separate a conditional/flow control statement from the actions that are taken; for example, you have:

if($lowrange < 0) { $lowrange = 0; print "\nYour number must be positi +ve. I have set it to 0 for you."; }
It's must easier to read if you do:
if ($lowrange < 0) { $lowrange = 0; print "\nYour number must be positive. I have set it to 0 for you. +"; }
Even a bit better is the following:
{ $lowrange = 0; print "\nYour number must be positive. I have set it to 0 for you. +"; } if ($lowrange < 0);
as this implies a non-critical conditional instead of a significant conditional.

I'd also try to be consistent when you add your \n's for printing; either do them all at the end or all at the beginning; the mix is somewhat distracting.

From a logic standpoint, you may want to round to the nearest int; if I enter "2.5" as the lower bound, the program won't find any primes, for example.

In the search-for-primes loop, you can use the last keyword instead of setting $i to an incrediable high value as to leave the loop early.

-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
It's not what you know, but knowing how to find it if you don't know that's important


In reply to Re: Mock my code! by Masem
in thread Mock my code! by Superlman

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.