in reply to Re: Recover a variable from a function
in thread Recover a variable from a function

I did that easily but it doesn't work:
use vars '$start'; sub Start_timer : Test(startup) { my $start = time(); cprint "#\x037Started at ", (strftime '%A %d %B %Y %H:%M:%S',localti +me($start)), "\x030\n"; } sub End_timer : Test(shutdown) { print time - $start; my $end = time; cprint "#\x037Ended at ", (strftime '%A %d %B %Y %H:%M:%S', localtim +e($end)),"\x030\n"; cprintf "#\x035 Total run time=>", $end-$start, " seconds\n"; cprintf ("%02d:%02d:%02d\x030\n",(gmtime($end-$start))[2,1,0]); }
And i have this following issue in my shell :
ok 243 - Logout ok Use of uninitialized value $MyTest::start in subtraction (-) at MyTest +.pm line 402. 1463646157#Ended at jeudi 19 mai 2016 10:22:37 Use of uninitialized value $MyTest::start in subtraction (-) at MyTest +ingSuite.pm line 407. # Total run time=>Use of uninitialized value $MyTest::start in subtrac +tion (-) at MyTest.pm line 408. 08:22:37

Replies are listed 'Best First'.
Re^3: Recover a variable from a function
by Corion (Patriarch) on May 19, 2016 at 08:47 UTC
      It works . Perfect . And the link is very useful. Many thanks , as usual Corion !