One yucky way to do this, would be to read the original source file for the N lines until where the use load is located (because I can know the line number from the call stak, but I would need the byte offst).

Other suggestions, anyone?

Eh... create an index file, next to the original source file, mapping the line number to the index? It's simple enough — error checking has been dropped, as this is just an example, and error checking distracts from the code that actually matters:
open SRC, "$source"; open IDX, ">$source.offset"; binmode IDX; while(<SRC>) { print IDX pack 'N', tell SRC; }
I did try it with CGI.pm this way:
use CGI; $source = $INC{'CGI.pm'};
Now, when you want the start of line 2990 (first line at is at offset 0, and its start offset is not stored):
my $line = 2990; open IDX, "$source.offset"; binmode IDX; seek IDX, 4 * ($line - 2), 0; read IDX, my($packed), 4; $offset = unpack 'N', $packed; open SRC, "$source"; seek SRC, $offset, 0; print "Line $line is:\n", scalar <SRC>;
which, for me, prints
Line 2990 is:
# Globals and stubs for other packages that we use.
This is indeed the line #2990 for my CGI.pm ($CGI::VERSION='2.752').

Note that this is Windows, and I did not bother to use binmode() on the source file. You must be consistent: either use binmode() both on creating the index file and seeking in the source file, or for neither.

My idea is that you have a make-like mechanism, much like Inline, and compare the modification dates on the index file and the module source file, and recreate the index file if it doesn't exist, or is out of date.


In reply to Re: Filepointer of source file inside source filter by bart
in thread Filepointer of source file inside source filter by liz

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.