in reply to mail question and book, and code
in thread mail question and book
You need to declare variables when you have use strict; see strict. Also when reading from they keyboard you need to use chomp:
#!/usr/bin/perl use strict; use warnings; print "How old are you?\n"; chomp (my $age = <>); print "What is your favorite color?\n"; chomp (my $color = <>); print "You are $age, and your favorite color is $color.\n";
Note that the second example is using chomp already, but missing declorations:
#!/usr/bin/perl use strict; use warnings; print "What is the radius of the circle?\n"; chomp (my $r = <>); my $diameter = (2 * $r); my $area = (3.14 * ($r ** 2)); my $cir = ($diameter * 3.14); print "Radius: $r\n Diameter: $diameter\n Circumference: $cir\nArea: $ +area\n";
References for learning Perl:
|
|---|