Skip to content

Instantly share code, notes, and snippets.

@pmakholm
Created April 10, 2013 11:59
Show Gist options
  • Select an option

  • Save pmakholm/5354001 to your computer and use it in GitHub Desktop.

Select an option

Save pmakholm/5354001 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use v5.12.0;
use File::Next;
use PPI;
my $basedir = shift // '.';
my $elements = shift // 'Token::Regexp';
my $files = File::Next::files( $basedir );
while(defined( my $file = $files->() )) {
next unless $file =~ /\.(?:pm|pl|t)$/;
my $doc = PPI::Document->new( $file, readonly => 1 )
or next;
for my $elem ( @{$doc->find($elements) || []} ) {
say $elem->content, " at $file:", $elem->line_number;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment