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

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.
  • Comment on Re^2: Calculating the time to execute commands on each element of an array

Replies are listed 'Best First'.
Re^3: Calculating the time to execute commands on each element of an array
by stevieb (Canon) on Sep 28, 2015 at 19:53 UTC

    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 } }