1. Numbers, Perl

    Write a program which tells you:

    • how many hours are in a year?
    • how many minutes are in a decade?
    • how many seconds old are you?

    Code:

    #!/usr/local/bin/perl
    print 24*365, ", ", 60*24*365*10, ", ", ((60*60)*((365*32)+(30*8))); 
    print "\n";
    

    Output:

    8760, 5256000, 42912000
    

    Harder: If I am 1031 million seconds old, how old am I?

    #!/usr/local/bin/perl
    print "1,031,000,000 seconds = ", 1031000000/60, " minutes", "\n";
    print "1,031,000,000 seconds = ", 1031000000/(60*60), " hours", "\n";
    print "1,031,000,000 seconds = ", 1031000000/(60*60*24), " days", "\n";
    print "1,031,000,000 seconds = ", 1031000000/(60*60*24*365.25), " years", "\n";
    

    Output:

    1,031,000,000 seconds = 17183333.3333333 minutes
    1,031,000,000 seconds = 286388.888888889 hours
    1,031,000,000 seconds = 11932.8703703704 days
    1,031,000,000 seconds = 32.6704185362638 years
    

    Notes: Easier to tie a string with an integer than in Ruby.

     
    1. learningtoprogram posted this