in reply to Calculating the time to execute commands on each element of an array

Do you have a question or is this a request for comments/critiques?

If the latter, are you satisfied with your results? If the former, where is the result less than satisfactory? Please include narrative description of your problem with this (large) snippet and error messages/warnings/inaccurate output.


++$anecdote ne $data

check Ln42!

  • Comment on Re: Calculating the time to execute commands on each element of an array
  • Download Code

Replies are listed 'Best First'.
Re^2: Calculating the time to execute commands on each element of an array
by shroh (Acolyte) on Sep 28, 2015 at 19:23 UTC
    Hi, This is a question, as you can see in the subroutine enable_unplanned_outage i have a code to calculate the total time taken by all the nodes/servers , same code i have to use in the subroutine disable_unplanned_outage. Since it is exactly same code, i was thinking of creating another subroutine which will do that for me.

      I don't have the time at the moment to go through it all line-by-line, but after a quick glance, it appears that you can move most of that code as-is to a new sub, then call it like this:

      for my $FQDN (@things){ my $start_time = time_and_log($FQDN); # do stuff with $FQDN time_and_log($FQDN, $start_time); }

      ...and in the sub...

      sub time_and_log { my $FQDN = shift; my $start = shift; if (! $start){ # do start stuff $start = time; return $start; } else { # use $start for calculations, # then log } }