Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-23 14:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found