Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

The naming convention for SomeModule.pm test code is SomeModule.t. This is not enforced in any way, but it's what everyone expects. | Well, it's what I expected, anyway. See Update Note 1 below.

Some comments on the is_lousy_prime() function code.

if ( $prime_candidate <= 0 ) { return 0; exit; }
The exit; statement in the code above will never be reached. No code in the function will be executed after the return 0; statement executes. There's another example of this unreachable-code syntax in the foreach loop further on in the function.

exit if $prime_candidate == 1 && return 0;
This is more involved, but essentially the same thing is happening: the exit built-in function will never be executed.
  • If the $prime_candidate == 1 expression is false, exit will not be executed because the if-condition is not true. (Update: The return 0 expression will not be executed because && short-circuits.)
  • If the $prime_candidate == 1 expression is true, the return 0 expression will be executed and will immediately return from the function; exit will not be executed.

And one more thing: Please, please choose a reasonable indentation style and stick to it!

Update:
Notes:

  1. After reading kcott's reply, I thought to myself "Yeah, I do seem to recall spending many happy hours watching files with exactly that nn_name.t format roll by during countless module installs." WTF?!? I think my confusion stems from my practice of writing test scripts with the naming format I mentioned as part of my personal code development best practices. I then conflated personal and general. Oh, well...


Give a man a fish:  <%-{-{-{-<


In reply to Re^2: Stupidest Prime Number detector ever!! (updated) by AnomalousMonk
in thread Stupidest Prime Number detector ever!! by Anonymous Monk

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-20 15:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found