#!/usr/bin/perl open(M,"mastercolor"); while() { chomp; next if /^#/; push @match, $_; } close(M); open(C,"customcolors.js"); while() { if (/addCustomColor\("(.*)","(#?[0-9a-f]{6})"\);/) { $cn = $1; $cc = $2; $cc= '#'.$cc if $cc !~ /^#/; next if ($dup{$cn.$cc}); push @colors, [$cn,$cc]; $dup{$cn.$cc}++; } } close(C); foreach $c (@colors) { $flag = 0; foreach $m (@match) { if ($c->[0] =~ $m) { push @{$mg{$m}}, $c; $flag++; } } push @{$mg{""}}, $c unless $flag; } foreach $m (@match,"") { foreach $c (sort { $a->[1] cmp $b->[1] } @{$mg{$m}}) { ($cn, $cc) = @{$c}; print "addCustomColor(\"$cn\",\"$cc\");\n"; } }