Programming Fundamentals/Functions/Perl: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
Creating |
(No difference)
|
Revision as of 04:32, 20 January 2017
variables.pl
#!/usr/bin/perl
sub get_f
{
my $f;
print "Enter Fahrenheit temperature: ";
$f = <>;
chomp($f);
return $f
}
sub calculate_c
{
my ($f) = @_;
my $c;
$c = ($f - 32) * 5 / 9;
return $c
}
sub display_result
{
my ($f, $c) = @_;
print $f . "° Fahrenheit is " . $c . "° Celsius", "\n";
}
sub main
{
my $f;
my $c;
$f = get_f();
$c = calculate_c($f);
display_result($f, $c);
}
main()
Try It
Copy and paste the code above into one of the following free online development environments or use your own Perl compiler / interpreter / IDE.