Here's one way to do it:
#!/usr/bin/perl -w
$pi = 3.141592654;
$circ = 2 * $pi * 12.5;
print "The circumference of a circle of radius 12.5 is $circ.\n";
We started this program with a typical #! line; your path to Perl may vary. We also turned on warnings.
The first real line of code sets the value of $pi to our value of p. There are several reasons a good programmer will prefer to use a constant value like this: it takes time to type 3.141592654 into your program if you ever need it more than once. It may be a mathematical bug if you accidentally used 3.141592654 in one place and 3.14159 in another. There's only one line to check to ensure you didn't accidentally type 3.141952654 and send your space probe to the wrong planet. It's easier to type $pi than p, especially if you don't have Unicode. Maintaining the program also will be easier in case the value of p changes.. Next, we calculate the circumference, storing it into $circ, and we print it out in a message. The message ends with a newline character because every line of a good program's output should end with a newline. Without it, you might end up with output looking something like this, depending on your shell's prompt:
The circumference of a circle of radius 12.5 is
78.53981635.bash-2.01$[ ]
The box represents the input cursor, blinking at the end of the line, and that's the shell's prompt at the end of the message. Since the circumference isn't 78.53981635.bash-2.01$, this should probably be construed as a bug. So, use \n at the end of each line of output.
Here's one way to do it:
#!/usr/bin/perl -w
$pi = 3.141592654;
print "What is the radius? ";
chomp($radius = <STDIN>);
$circ = 2 * $pi * $radius;
print "The circumference of a circle of radius $radius is $circ.\n";
This is like the last one, except now we ask the user for the radius, and then we use $radius in every place where we previously used the hardcoded value 12.5. If we had written the first program with more foresight, we would have had a variable named $radius in that one as well. Note that we chomped the line of input. If we hadn't, the mathematical formula would still have worked because a string like "12.5\n" is converted to the number 12.5 without any problem. But when we print out the message, it would look like this:
The circumference of a circle of radius 12.5
is 78.53981635.
The newline character is still in $radius, even though we've used that variable as a number. Since we had a space between $radius and the word "is" in the print statement, there's a space at the beginning of the second line of output. The moral of the story is: chomp your input unless you have a reason not to do it.