Last active
November 19, 2016 10:39
-
-
Save NaotoKumagai/8a83defca6a37da43c6d to your computer and use it in GitHub Desktop.
【Perl】Jsonのkey名抽出
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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