Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created April 15, 2013 06:43
Show Gist options
  • Select an option

  • Save hitode909/5386164 to your computer and use it in GitHub Desktop.

Select an option

Save hitode909/5386164 to your computer and use it in GitHub Desktop.
PerlのソースコードからStringだけ探して標準出力に表示する
# perl perl_string_ranking.pl ~/co/Plack/lib/**/**.pm | sort | uniq -c | sort -n -k 1
# Stringリテラルだけ出力する
# sortすると重複を探すときに使える予定
use strict;
use warnings;
use PPI;
use Perl6::Say;
sub parse {
my ($file) = @_;
warn $file;
my $document = PPI::Document->new($file);
my $tokens = $document->find('PPI::Token::Quote');
return unless $tokens;
map {
$_->content;
} @$tokens;
}
for my $file (@ARGV) {
for my $token (parse($file)) {
$token =~ s/\s+/ /g;
say $token;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment