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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.