Hi Jason,

To start with you are going to get quite a few replies that will tell you to
use strict and enable warnings because that is what good perl programers do.
:-)

#!/usr/bin/perl
use strict;
use warnings;

#Name:circumf


Strict basically forces you to scope your variables, there is a lot of
information about this in all kinds of tutorials so I am not going to repeat
it all here or pretend that I would even be able to do so. At least for
starters it is enough to know that you can put "my" infront of every new
variable that you want to use to decalre it as in use and that this variable
will only be available in the subroutine that you have declared it in
(basically the variable declared before a { is not available after the {
which is the simplest way to put it for a beginner in my humble opinion).

Warnings are much simpler as the name says it enables warnings in perl, and
you will be informed of potential incorrect ways of writting code, like and
array element being addressed as @array[2] will cause perl to write a
warning to STDERR complaining that you should have used $array[2] instead.

Other then that you might want to have a little less trust in your users,
and verify that what they put in is actually a number and not a bit of text
or something like that, but as you say this is just a program to start to
learn so it might be a bit overkill to check your own input.

Regards,

Rob Coops

On Thu, Jun 19, 2008 at 8:55 AM, Jason B <[EMAIL PROTECTED]> wrote:

> I'm really new to programming and this is my first perl prog.  I'm looking
> for any advice or comments on this script.
>
> (I don't want to develop bad habits from the start)
>
> Thx.
>
> #!/usr/bin/perl
>
> #Name:circumf
> #Date:Jun19/08
> #Author:Bornhoft, J
> #Purpose:to calculate the circumference of a circle
>
> print "Hi. I'm going to help you calculate the circumference of a
> circle\n";
>
> $pi = 3.141592654;
>
> print "What is the radius of the circle?: ";
> chomp($radius = <STDIN>);
>
> if ($radius < 0) {
>    $radius = 0;
>    print "Psst...\nThe radius can\'t be less than zero.\nLet me help you
> out there\n";
> }
>
> $diameter = ($radius * 2);
> $area = ($pi * ($radius ** 2));
> $circumf = ($diameter * $pi);
>
> print " Radius: $radius\n Diameter: $diameter\n Area: $area\n And
> finally!!!\n Circumference: $circumf\n";
>

Reply via email to