in reply to grepping out global vars?

It's actually really easy to write a B:: module to do this. I spent a few minutes on this:

package B::FindGlobals; use B::Utils 'walkallops_filtered'; sub compile { return sub { walkallops_filtered( \&gv_only, \&report_global ); }; } sub gv_only { my $op = shift; return unless $op->name() =~ /^gv/; return unless $B::Utils::file eq $0; return 1; } sub report_global { my $op = shift; printf "%s: % 4d %s\n", $B::Utils::file, $B::Utils::line, $op->gv()->NAME(); } 1;

Install B::Utils, then run it on the file you want to check with perl -MO=FindGlobals filename.pl. You'll have to stuff this module somewhere in @INC under a B directory.

Replies are listed 'Best First'.
Re^2: grepping out global vars?
by dragonchild (Archbishop) on Jan 18, 2005 at 14:11 UTC
    Question: Do you have to put the FindGlobals package in the B:: namespace for B::Utils to do its work?

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      Not for B::Utils; that should work anywhere. You do have to put B::FindGlobals in an appropriate location for O to do its work though. That's the magic -MO=FindGlobals notation.

        Next Question: Do you have to use O in order to get the benefits of B? In other words, would perl -MGlobalFinder script.pl have worked just as well?

        Being right, does not endow the right to be rude; politeness costs nothing.
        Being unknowing, is not the same as being stupid.
        Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
        Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.