in reply to Re: Passing a duration time from 1 subroutine to another
in thread Passing a duration time from 1 subroutine to another

Thank you for the clarification, run_test() NOT run_tests(). This code is very long, so I purposely cut it short for the reader's sake. here's a better code description:

sub new { my ($class) = @_; # Initialize attributes my $self = { _test_name => undef, # Name of the current test _testcase_name => undef, # Name of the current testcase _test_statistics => {}, # Statistics for the current + test }; bless $self, $class; # Two-argument version used to support inhe +ritance return $self; }

here is where the run_test() is called and how cleanup_test() is used

sub run_test{ my ($self, @tests) = @_; # Setup test system. $self->_setup_test_system(); # Run each test. TEST: for my $test_name (@tests) { # Setup everything necessary for current test. $self->setup_test_system($test_name); # Run each testcase for current test. TESTCASE: while ($self->__fetch_next()){ my $start = gettimeofday(); my $is_pass = $self->_run_testcase(); my $end = gettimeofday(); my $duration = $end - $start; if (!$is_pass && $self->{_abort_on_failure}) { print "\nFailure occurred,for $test_name.\n"; last TESTCASE; # Exit loop } } # Cleanup at end of test. $self->cleanup_test(); # Clean up test system. $self->_cleanup_test_system(); return $self->{_test_system_stats}{num_tests_failed}; } }

Replies are listed 'Best First'.
Re^3: Passing a duration time from 1 subroutine to another
by 1nickt (Canon) on Aug 21, 2015 at 05:12 UTC

    Cool, thanks for replying. The best thing is always if you can reduce the problem to its simplest example; this may mean writing a new, small script to show your issue. People want to be able to copy your sample code right into a file on their computer, run it as is, see the error, make some changes and implement a fix, and post that back here. It's more difficult to help when you can only think about the problem in abstract terms.

    For example, now that you've posted your object constructor, I wonder whether you need to construct an object at all. You mention inheritance in a comment, but your code looks like a standalone program. Is there a reason why your code doesn't simply call subroutines as it moves through its flow? Why do you think you need to make this code OO?

    As an aside, the constructor for an object usually looks more like this:

    sub new { my $class = shift; my %args = @_; my $self = {}; # validate the args # do stuff to populate $self bless $self, $class; return $self; }
    Hope this helps!

    The way forward always starts with a minimal test.