in reply to time diff in minutes

Try this... Although this code can break easily.
#!/usr/bin/perl use strict; my $t1 = "1245"; my $t2 = "0150"; Get_Time_Diff( $t1, $t2 ); sub Get_Time_Diff { my @times = @_; for my $i (0 .. $#times) { $times[$i] += 1200 if ( $times[$i] < '1200' ); $times[$i] = substr( $times[$i], 0, 2 ) * 60 + substr( $times[$i], 2, 4 ); } my $diff = $times[1] - $times[0]; print "Time difference is: $diff \n"; }

Replies are listed 'Best First'.
Re^2: time diff in minutes
by Boldra (Curate) on Aug 13, 2009 at 06:19 UTC
    Here's why I don't like the code in this answer:
    1. It gets the length of @times with $#times, but then later assume it has only two elements
    2. It prints, but the sub is called 'Get'
    3. It assumes times < 1200 are all in the afternoon!
    4. It doesn't use warnings
    5. It uses quotes to define constant integers

    Please consider DateTime


    - Boldra