Thanks to everyone who responded. I don't want to spam the place responding to everyone, so I hope you all don't mind just this one post. Also, thanks for showing me modules and functions that are new to me. I will look into them further if I need them later. For something as simple as this, I decided to just do a little math myself.
I hope that you all aren't disappointed that I just used return instead of printf in my subroutine. The whole print vs. printf conversation seems best left for a completely independent thread.
Leap seconds? Where have I been? :)
Looks like the -> may have something to do with objects and classes, which I am not versed in yet. I have read over several perldocs on objects and barely get it. I haven't dealt with objects in any code I have written. Objects seems to be another topic left to an independent thread. I think I would need to see a full example all together to begin to grasp the subject.
Again, thank you all for helping me out. Have some cookies!
use strict; use warnings; #I made my variables more semantic. @times was just to general, %durat +ions is a better word, thanks to those who used it. :) my %durations = ( 's1' => [qw(3:58 2:48 4:28 5:06 6:50 5:33 4:05 3:29 4:48 6:19)], 's2' => [qw(5:33 5:08 5:30 6:52 6:56 6:48 6:34 5:43 6:50 8:32 6:22 8 +:39)], 's3' => [qw(5:21 8:01 5:37 7:19 5:46 7:44 6:43 7:17 8:02 6:50 7:54 8 +:44)], ); # %durations are minutes and seconds. sub get_duration { my ($var) = @_; my $total_seconds; for my $duration (@{$durations{$var}}) { my ($minutes,$seconds) = split(':',$duration); # The change here m +ade the line much easier to read. :) $total_seconds += ($minutes * 60) + $seconds; # This eliminated my + need to create another array then adding the values of that array. : +) } my $total_minutes = int($total_seconds/60); #I totally forgot about +int. :S my $total_hours = int($total_minutes/60); my $print_seconds = $total_seconds % 60; my $print_minutes = $total_minutes % 60; return $total_hours.':'.$print_minutes.':'.$print_seconds."\n"; } print get_duration('s1'); print get_duration('s2'); print get_duration('s3');
In reply to Re^2: Getting times (weeks, days, hours, minutes, seconds)
by Lady_Aleena
in thread Getting times (weeks, days, hours, minutes, seconds)
by Lady_Aleena
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |