From my limited understanding of how Perl works I doubt it is possible to get the original text that comprises your program at runtime without directly reading the source file. The logic for this assertion is based on how Perl actually executes the textfile that contains your code.

When you run a Perl program this is what happens:

0. First the Perl executable reads textfile that comprises your code.

1. Next comes: The Compilation Phase which converts your textfile program into a data structure called a parse tree. During this process it discards superfluous elements like whitespace and comments.

2. Next it moves on to the optional Code Generation Phase.

3. Next comes: The Parse Tree Reconstruction Phase where it reanimates the program by reconstructing the parse tree. This too is optional and occurs only if the phase 2 code generation occurs and you chose to generate bytecode.

4. Finally comes: The Execution Phase where the interpreter takes the parse tree data structure and executes it. This is runtime. Because it executes the parse tree data structure rather than the original textfile you think of as your program, when your program runs it is in the form of Perl's internal opcodes not the original code that generated them.

I would therefore suggest that what you want to do may not be possible as the source code that you wish to get no longer exists per se. It is still in the source file but is not being used by Perl in its original form anymore.

Chapter 18 of the Camel (3rd ed) goes into this in more detail. Thankfully I don't have to understand this to write Perl code - otherwise I would be stuffed because I don't!

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: Using @{"_<$filename"} by tachyon
in thread Using @{"_<$filename"} by bikeNomad

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.