Skip to content

Instantly share code, notes, and snippets.

@marked
Last active November 14, 2019 20:07
Show Gist options
  • Save marked/fae8f25626d6f7117a9313c71cb57cfa to your computer and use it in GitHub Desktop.
Save marked/fae8f25626d6f7117a9313c71cb57cfa to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use warnings;
use strict;
use autodie;
my @lines = <>;
chomp @lines;
my %adjadj;
foreach my $l (@lines) {
my ($combo, $reduc) = split / /, $l ;
if ($adjadj{$reduc}) {
push(@{$adjadj{$reduc}}, ($combo));
} else {
$adjadj{$reduc} = [ $combo ];
}
}
my %dirs;
foreach my $aa (keys(%adjadj)) {
$aa =~ /([A-Z][a-z]+)([A-Z][a-z]+)/;
my ($a1, $a2) = ($1, $2);
if ( ! $dirs{$a1}) {
system "mkdir $a1";
$dirs{$a1} = 1;
}
open my $fh, ">", "$a1/$a2";
my $js = join "\n", sort(@{$adjadj{$aa}});
print $fh "$js\n";
close $fh;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment