in reply to Mock my code!

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

Replies are listed 'Best First'.
Re: Re: Mock my code!
by Hofmator (Curate) on Sep 06, 2001 at 18:04 UTC

    Good advice, Masem. But your if statement example doesn't work ...

    do { # not without the do $lowrange = 0; print "\nYour number must be positive. I have set it to 0 for you. +"; } if ($lowrange < 0);
    this form of if (or unless, foreach, while, until) only works on simple statements, not on blocks.

    -- Hofmator