PERL - <STDIN>
<STDIN> stands for standard input. It can be abbreviated by using simple <>. By declaring a scalar variable and setting it equal to <STDIN> we set the variable equal to whatever will be typed by our user at the command prompt. Observe:whatismyage.pl:
#! usr/bin/perl print "How old are you?"; $age = <>; print "WOW! You are $age years old!";
How old are you?:
Let's take this example one step further and also request the favorite color of our user.
agencolor.pl:
#! usr/bin/perl print "How old are you?"; $age = <>; print "What is your favorite color?"; $color = <>; print "You are $age, and your favorite color is $color.";
Age 'N' Color:
PERL - Beginning Scripting
You now have the knowledge required to code some mathematical scripts like the following.circle.pl:
#! usr/bin/perl print "What is the radius of the circle?"; chomp ($r = <>); $diameter = (2 * $r); $area = (3.14 * ($r ** 2)); $cir = ($diameter * 3.14); print "Radius: $r\n Diameter: $diameter\n Circumference: $cir\n Area: $area";
0 comments:
Post a Comment