Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

chromatic (983)

  (email not shown publicly)

Blog Information [] Profile for chr0matic []

Journal of chromatic (983)

Monday April 25, 2005
01:46 AM


[ #24356 ]

Why call walkoptree() yourself (see when you have the power of XPath (at least as much as Class::XPath supports?


use strict;
use warnings;

use B::XPath;

use vars qw( $foo $bar );

sub some_sub
    my $x = shift;
    $foo  = $x;
    print "\$x is $x\n\$foo is $foo\n";

my $node = B::XPath->fetch_root( \&some_sub );

for my $bar ($node->match( '//gvsv[@NAME="foo"]' ))
        "Found global '%s' at %s:%d\n  (defined at %s:%d)\n",
        map { $bar->$_ } qw( NAME find_file find_line FILE LINE )

I'm sure you're on the edge of your seat for the output:

$ perl
Found global 'foo' at
  (defined at /usr/lib/perl5/5.8.6/
Found global 'foo' at
  (defined at /usr/lib/perl5/5.8.6/

There are two drawbacks (besides the fact that it's a proof of concept and not releasable yet): Class::XPath has little axis support and you have to know an awful lot about the structure of the optree for which you want to search. I think the latter is solvable, but it will require more thought.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.