#!/usr/bin/perl -w # # hextoswatch.pl - Extract colour strings from random code or HTML. # Currently only looks for 0xRRGGBB and #RRGGBB. # # perl hextoswatch.pl < source.txt > swatch.html # # and then open swatch.html in a browser! # # Chars that make up a colour string: # my $hexRegex = '0-9a-zA-Z'; my $colRegex = "#x$hexRegex"; my @hexSs = (); while ( ) { chomp; my @words = split /[^$colRegex]/; push @hexSs, (grep /^(0x|#)[$hexRegex]{6}$/, @words); } map { s/^(0x|#)(......)/$2/ } @hexSs; #print "Content-type: text/html\n\n"; print "\n\n"; print "\n"; print "Colour swatches from random text\n"; print "\n\n"; print "\n"; print ""; my $cell = 0; foreach my $hex ( @hexSs ) { print ""; if ( $cell++ gt 4 ) { $cell=0; print "\n" } } print "
", "$hex

", "$hex
\n";