subroutines.pl सम्पादन

#!/usr/bin/perl

# This program asks the user for a Fahrenheit temperature,
# converts the given temperature to Celsius,
# and displays the results.

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()

कोशिश करो सम्पादन

निम्न कोड मुफ्त ऑनलाइन विकास के वातावरण में से एक में ऊपर कॉपी और पेस्ट करो या अपने खुद के कम्पाइलर/इंटरप्रेटर/आईडीई का उपयोग करें।

यह भी देखें सम्पादन