Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: What is wrong with this code?

by ww (Archbishop)
on Jul 24, 2011 at 01:09 UTC ( [id://916364]=note: print w/replies, xml ) Need Help??


in reply to What is wrong with this code?

In addition to toolic's and jethro's catches, note that the syntax of your formula for the area of a square isn't correct. It will give the area as (side times 2); you want $square_side**2 ($square_side to the power of 2, eg, squared).

Also, check your spelling (parallelogram and equilateral, for example), lest you teach li'l bro' errors and review your geometry text to check your title in the triangle formula.

Other suggestions, depending on your taste:

  • When you wish to include info like your formulae in a non-executable format, include it inside POD markup, used as a block comment:
    =head formulae $area_square=$side**2; ... =cut
  • Unless you plan to expand this greatly, you'll have less overhead (and more portability) if you simply define pi as 3.141659 3.14159 (Thanks, eyepopslikeamosquito) rather than using Math::Trig.
  • You may wish to provide the user with a choice to exit or restart. Various techniques are available.
  • IMO using the equal sign in your answer lines (and generally, using the equals sign in any response to a user) risks making your code harder to proof ("Is that "=" an assignment or a symbol?"). I find usage such as print "Answer:  " . function(); or similar friendlier.

Updated: to acknowledge jethro's excellent point, posted as I fiddled with minutia and eyepopslikeamosquito's catch on my brain-fart.

Replies are listed 'Best First'.
Re^2: What is wrong with this code?
by jdporter (Paladin) on Jul 24, 2011 at 02:22 UTC
    you'll have less overhead (and more portability) if you simply define pi as 3.14159

    Blech. Get maximum precision without Math::Trig (and without programmer error):

    $PI = 4 * atan2(1,1);
    I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.
Re^2: What is wrong with this code?
by eyepopslikeamosquito (Archbishop) on Jul 24, 2011 at 02:05 UTC

    you'll have less overhead (and more portability) if you simply define pi as 3.141659 rather than using Math::Trig.
    Of course, that should read 3.14159. Or even 3.14159265358979323846264338327950288419716939937510 :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://916364]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-03-29 10:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found