#!/usr/bin/perl -w use strict; my %symbolToListing; my %symbolToUniques; my $curName = ''; my $curSymbol = ''; my $isUnique = 0; foreach my $line (`grep -E "^N:|^G:|^F:" monster.txt`) { chomp $line; if ($line =~ /^N:/) { if ($curName and $curSymbol) { if (not exists $symbolToListing{$curSymbol}) { $symbolToListing{$curSymbol} = []; $symbolToUniques{$curSymbol} = []; } if ($isUnique) { push @{$symbolToUniques{$curSymbol}}, $curName; } else { push @{$symbolToListing{$curSymbol}}, $curName; } } ($curName) = $line =~ /N:\d+:(.*)$/; $curSymbol = ''; $isUnique = 0; } elsif ($line =~ /^G:/) { ($curSymbol) = $line =~ /G:(\w:\w)$/; } elsif ($line =~ /^F:.*UNIQUE/) { $isUnique = 1; } } foreach my $symbol (keys %symbolToUniques) { if (scalar @{$symbolToUniques{$symbol}} and scalar @{$symbolToListing{$symbol}}) { print "Uniques with symbol $symbol: " . join(", ", @{$symbolToUniques{$symbol}}) . "\n"; print " conflicts with monsters: " . join(", ", @{$symbolToListing{$symbol}}) . "\n\n"; } elsif (scalar @{$symbolToUniques{$symbol}} > 1) { print "Uniques with symbol $symbol conflict with each other: " . join(", ", @{$symbolToUniques{$symbol}}) . "\n\n"; } }