#!/usr/bin/perl -wT # # Author name:Aljerin L. Butler, Jr. # Creation date:April 26, 2011 # # Description: # bs_table.pl - create a table of browser-safe colors # Colors consist of rgb hex codes with a combination # of any of the following hex digits: # 00, 33, 66, 99, cc, ff # # Create anonymous array of browser-safe colors # my $colors = [ '00', '33', '66', '99', 'CC', 'FF' ]; # Generate color table by combining color codes through 3 while loops, # the outer loop for red and the inner loop for blue # each row in color table will consist of 12 rgb combinations # giving a total of 6**3=216 colors # Open file for color table output open(TABLE, ">>browser_safe.txt") or die "can't open browser_safe.txt:$!\n"; # initialize red array my @red=@$colors; # declare loop variables my ($r, $g, $b, $rgb_code); my @rgb_row=(); foreach $r (@red) { my @green=@$colors; # initialize green array foreach $g (@green) { my @blue=@$colors; # initialize blue array foreach $b (@blue) { $rgb_code=$r.$g.$b; push (@rgb_row, $rgb_code); # Fill color code array # When color code array gets to 12 colors, ship it to browser_safe.txt if (scalar @rgb_row==12) { @rgb_row=sort @rgb_row; # sort color codes in ascending order print "@rgb_row \n"; print TABLE "@rgb_row \n"; @rgb_row=(); # Clear @rgb_row for next set of colors } } # End of blue loop } # End of green loop } # End of red loop close TABLE or die "can't close browser_safe.txt:$!"; print "Color code table generation completed \n";