Skip to content

Instantly share code, notes, and snippets.

@NaotoKumagai
Last active November 19, 2016 10:39
Show Gist options
  • Save NaotoKumagai/8a83defca6a37da43c6d to your computer and use it in GitHub Desktop.
Save NaotoKumagai/8a83defca6a37da43c6d to your computer and use it in GitHub Desktop.
【Perl】Jsonのkey名抽出
#!/usr/bin/perl
for(@ARGV) {
open(IN, $_) || die "$!";
for(<IN>) {
# 通常のjsonだと m/"(\w*?)":["|\d]/g
for my $match ( m/"(\$?\w*?)":["|\d|true|false]/g ) {
$is_match = 0;
for my $_ (@list) {
if($_ eq $match) {
$is_match = 1;
last;
}
}
unless($is_match) {
push (@list, $match);
print $match."\n";
}
}
}
close(IN);
open(OUT, ">key_list.log") or die "$!";
for my $hoge (@list) {
printf OUT $hoge."\n";
}
close(OUT);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment