Is there any way for a script to get a reference to the main sub? I was trying to do something like &main;, &:: and &; but obviously none of those worked or I wouldn't be asking now. I'd like to get a code reference to the currently executing contex for use in peeking at the innards of stuff like (?{1}). I also tried using judo like B's main_cv but that didn't get me anywhere either - it just produces an exception. Help? The code is an example of what I'm actually doing. I'm thinking that if I can get a proper code reference that this will work better since perhaps however main_cv works it isn't getting whatever I'm looking for (or then why else would it produce exception errors?)
use B 'main_cv';
use B::Deparse;
$deparse = B::Deparse->new;
# This prints "{}\n" which doesn't seem right
print $deparse->deparse_sub(main_cv), $/;
$qr = qr|(?:.(?{print $deparse->deparse_sub(main_cv), $/}))+|;
for (0 .. 9) {
print "$_\n";
$text = ' ' x $_;
$text =~ $qr;
}
__SIG__
use B;
printf "You are here %08x\n", unpack "L!", unpack "P4", pack
"L!", B::svref_2object(sub{})->OUTSIDE;
-
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.
|