Skip to content

Instantly share code, notes, and snippets.

@amatubu
Created March 15, 2013 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amatubu/5169355 to your computer and use it in GitHub Desktop.
Save amatubu/5169355 to your computer and use it in GitHub Desktop.
Create spice matrix
#!/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