Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Note that __LINE__ is usually relative to the top of the script's file:

print __LINE__, "\n"; print __LINE__, "\n"; eval {print __LINE__, "\n";}; __OUTPUT__ 6 7 8

The preceeding code prints three sequential numbers. I bring this up because it could be guessed (or hoped) that __LINE__ might be relative to the top of the code being processed in the eval block. In fact, it is not, if it uses eval's {block} syntax.

However, __LINE__ will return a different result if you wrap the eval'ed code in quotes. See the following code:

print __LINE__, "\n"; print __LINE__, "\n"; eval "print __LINE__,qq/\n/; print __LINE__,qq/\n/; die()"; print $@, "\n"; print __LINE__, "\n"; __OUTPUT__ 6 7 1 3 Died at (eval 1) line 5. 12

As you can see, that code prints the 6 and 7 as absolute file linenumbers. But the 1 and 3 are loosely relative to the quoted eval material. The "line 5" generated by trapping the die shows the odd behavior that in the case of lines of code eval'ed within quotes line numbers seem to skip a number for each line. Finally, the printing of '12' indicates that once back outside the eval function, the original numbering scheme resumes, unaffected by eval's apparent reset of __LINE__. So line must be localized within quoted eval strings.

I'd be interested in seeing any documentation for this behavior.


Dave


"If I had my life to do over again, I'd be a plumber." -- Albert Einstein

In reply to Re: Re: Line Numbers by davido
in thread Line Numbers by Sprad

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 having a coffee break in the Monastery: (3)
As of 2024-04-24 01:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found