Hi

PadWalker has a handy function peek_sub() to identify all private vars in a sub, but lacks a method to do so with package vars.

DB<318> $code = sub { my $a ** $b ** $bla::c } DB<319> x peek_sub($code) 0 HASH(0x3d161a8) '$a' => SCALAR(0x3d18da0) -> undef DB<320>

What's the best way to achieve this, except parsing the text output of B::Concise for GVs? (is this even reliable?) °

I think I asked this before, but who knows what changed in the meantime :)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

UPDATE

°) #<-- comments added

D:\>perl -MO=Concise,bla -e "sub bla {@a = ($b, my $c)}" main::bla: 9 <1> leavesub[1 ref] K/REFC,1 ->(end) - <@> lineseq KP ->9 1 <;> nextstate(main 2 -e:1) v ->2 8 <2> aassign[t5] KS/COM_AGG ->9 - <1> ex-list lKP ->5 2 <0> pushmark s ->3 - <1> ex-rv2sv sK/1 ->4 3 <#> gvsv[*b] s ->4 #<-- $::b 4 <0> padsv[$c:2,3] sM/LVINTRO ->5 #<-- my $c - <1> ex-list lK ->8 5 <0> pushmark s ->6 7 <1> rv2av[t2] lKRM*/1 ->8 6 <#> gv[*a] s ->7 #<-- @::a -e syntax OK

In reply to Inspecting package vars in a sub by LanX

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.