mmartin has asked for the wisdom of the Perl Monks concerning the following question:
my %months = ('Jan'=>1, 'Feb'=>2, 'Mar'=>3, 'Apr'=>4, 'May'=>5, 'Jun'=>6, 'Jul'=>7, 'Aug'=>8, 'Sep'=>9, 'Oct'=>10, 'Nov'=>11, 'Dec'=>12 ); calcTime(); sub calcTime { # These will hold the 'timelocal' for the current OWNER and curren +t WAITER being processed. my $ownTime; my $waitTime; # Loop through all the records and calculate time diff between an +'OWNER' and any 'WAITING' users up until the next 'OWNER'. for (my $x = 0; $x <= $#records; $x++) { #If the current line at the first elemnt is equal to 'OWNER' t +hen... if ($AoA[$x][0] eq 'OWNER') { for (my $y = $x+1; $y <= $#records; $y++) { if ($AoA[$x][0] ne $AoA[$y][0] && $AoA[$x][2] eq $AoA[ +$y][2] && !(exists $AoA[$y][13])) { #Splits field containg the 'TIME' into 3 seperate +variables (hours, minutes, seconds) my ($ohour, $omin, $osec) = split ':', $AoA[$x][10 +]; my ($whour, $wmin, $wsec) = split ':', $AoA[$y][10 +]; for (my $i = 0; $i <= $#records; $i++) { for (my $j = 0; $j <= 13; $j++) { print "$j. $AoA[$i][$j]\n"; } } #********************************* Getting error below from $ownT +ime, when using $AoA[$x][12] instead of $AoA[$x][10] **************** +************* #Convert into time $ownTime=timelocal($osec, $omin, $ohour, , $AoA[$x +][12], $months{ $AoA[$x][11] }, $year); $waitTime=timelocal($wsec, $wmin, $whour, , $AoA[$ +x+1][12], $months{ $AoA[$x+1][11] }, $year); #Calculate time difference between. my $timeDiff = $waitTime-$ownTime; $timeDiff = $timeDiff/60; $timeDiff = sprintf '%.1f minutes', $timeDiff; #Add the time difference to the end of the 'WAITER +S' line in @AoA and print it out. $AoA[$y][13] = $timeDiff; } #END IF } #END FOR-->$y } #END IF } #END FOR-->$x }
|
|---|