Hallo Monks,
I am trying to find a way to dynamically determine the current line being executed in my script.
I have a batch script which I accumulate a progress report or log whilst it is running and then output the log to a file on completion. I wish to add the current line number being executed in the script to each instance in the report
The following describes a snippet of code to demonstrate my requirement. I have annotated the code with line numbers for demonstration purposes
1. #!/usr/bin/perl 2. use warnings; 3. use strict; 4. 5. my @log ; 6. . . . 25. my $success = &Get_Item_From_File ($file) 26. 27. if ($Success) { 28. $_ref_DB_DD_OSD = &Get_DB_OSD ($_ref_Model) 29. } 30. else { 31. push (@log, "Read $file not successfull" . "31") ; 32. } . . . 1024 print <FILE> @log ; 1025 exit ; .
The following demonstrates the hard coded method at line 31, but if there is a way of determining this dynamically then this would reduce the need to have to manually update the hard coded value whenever the script is modified.
I envisage substituting line 31 as follows:
push (@log, "Read $file not successfull" . &function_returning_current_line) ;
or anything similar; i.e. Get a near enough line number before the call to push etc
Any help would be greatly appreciated
Best regards
Lucas Redding AKA Bearslumber
In reply to How to determine current line executing in Script by bearslumber
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |