Think about Loose Coupling | |
PerlMonks |
Re: Re: Line Numbersby davido (Cardinal) |
on Oct 17, 2003 at 21:42 UTC ( [id://300179]=note: print w/replies, xml ) | Need Help?? |
Note that __LINE__ is usually relative to the top of the script's file:
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:
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 Section
Seekers of Perl Wisdom
|
|