Created
March 15, 2013 11:49
-
-
Save amatubu/5169355 to your computer and use it in GitHub Desktop.
Create spice matrix
This file contains 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 | |
use strict; | |
use warnings; | |
use utf8; | |
my %spices; | |
my %blends; | |
# ブレンドリストを開く | |
open my $blend_file, "blendlist.txt"; | |
die "ブレンドリストが開けません。" if !$blend_file; | |
# ブレンドのカウント | |
while ( my $blend = <$blend_file> ) { | |
if ( $blend =~ m/(\w+)\s(\w+)/ ) { | |
my ( $spice1, $spice2 ) = sort ( $1, $2 ); | |
$spices{$spice1}++; | |
$spices{$spice2}++; | |
# マトリックス | |
$blends{$spice1}{$spice2} = 1; | |
$blends{$spice2}{$spice1} = 1; | |
} | |
} | |
# マトリックス表を作成 | |
my %spice_blend_matrix; | |
open my $matrix_file, ">", "matrix.txt"; | |
for my $spice1 ( sort keys %spices ) { | |
for my $spice2 ( sort keys %spices ) { | |
if ( $spice1 ne $spice2 ) { | |
$spice_blend_matrix{$spice1} .= $blends{$spice1}{$spice2} || "0"; | |
} else { | |
$spice_blend_matrix{$spice1} .= " "; | |
} | |
} | |
print $matrix_file "$spice_blend_matrix{$spice1}\n"; | |
} | |
close $matrix_file; | |
exit 0; | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment