8<--------------------------------------------------------------------------- #!/usr/bin/perl -w # # Exersize 8.6.1 solution. # # Raymond Fellers, Ph.D. # csci44a@yahoo.com # csci44a Perl I # Chabot College # use strict; print "Type in the height and width of a rectangle,\n"; print "and I will tell you the area.\n"; print "What is the height in meters? "; my $h = <>; print "What is the width in meters? "; my $w = <>; print "The area is ", area($h,$w)," square meters.\n"; exit; sub area { my ($height,$width) = @_; return $height * $width; } 8<--------------------------------------------------------------------------- #!/usr/bin/perl -w # # Exersize 9.8.1 solution. # # Raymond Fellers, Ph.D. # csci44a@yahoo.com # csci44a Perl I # Chabot College # # THIS WAS A POORLY WRITTEN PROBLEM, # THERE IS NO SOLUTION OR GRADE FOR THIS ONE. 8<--------------------------------------------------------------------------- #!/usr/bin/perl -w # # Exersize 9.8.2 solution. # # Raymond Fellers, Ph.D. # csci44a@yahoo.com # csci44a Perl I # Chabot College # use strict; my @a = (1, 2, 3); my @b = (4, 5, 6); print "Before swap, array \@a contains @a.\n"; print "Before swap, array \@b contains @b.\n"; arraySwap(\@a,\@b); print "After swap, array \@a contains @a.\n"; print "After swap, array \@b contains @b.\n"; exit; sub arraySwap { my ($arA, $arB) = @_; for( my $i=0; $i<@$arA; $i++ ) { my $tmp = $arA->[$i]; $arA->[$i] = $arB->[$i]; $arB->[$i] = $tmp; } return; }