a> some random text ---------------- b> b> a few random b> lines b> b> of more b> random b> b> text **************** c> some more c> c> random c> text c> a> some random text ---------------- b> b> a few random b> lines b> b> of more b> random b> b> text **************** c> some more c> c> random c> text c> #### @foo = ( { a => 'some random text' b => ' a few random lines of more random text ' c => 'some more random text ' }, { a => 'some random text' b => ' a few random lines of more random text ' c => 'some more random text ' }, .. and so on .. ); #### bri red grn blu 0 0 0 0 1 0 0 0 2 0 0 0 .. 99 0 0 0 100 0 255 255 101 0 250 255 102 0 246 255 .. #### CLASS EXPRESSION ([pixel] >= 242 AND [pixel] <= 242 STYLE COLOR 200 72 127 END END CLASS EXPRESSION ([pixel] >= 175 AND [pixel] <= 175 STYLE COLOR 191 236 0 END END .. #### while () { # remove leading whitespace & newline from end # and split the row on whitespace my @r = chomp && s/^\s+// && split /\s+/; # create a key in lut hash using rgb vals push @{$lut{"$r[1].$r[2].$r[3]"}}, $r[0]; } while (my ($k, $v) = each %lut) { $k =~ s/\./ /g; # replace . in hash key with space my @v = sort @$v; # sort the color brightness array to get # min/max values print OUTFILE "CLASS\n" . " EXPRESSION ([pixel] >= $v[0] AND [pixel] <= $v[$#v]\n" . " STYLE\n" . " COLOR $k\n" . " END\n" . "END\n"; }