It seems to me that I could compare with names from the list which on my Linux machine is in /usr/share/X11/rgb.txt (and add a check for colors of the form #rrggbb, no reason to exclude those). Can I expect that list to be standard on all systems (Linux, Windows, Macs)? Even if it is standard, is that the best way to do it?

Yes, /usr/share/X11/rgb.txt should be part of standard X11, so you should be able to use it on (almost) any Unix system running X11. Windows is something completely different. You won't find the /usr/share/X11 on a native Windows. MacOS X inherits from Unix, but does many things differently. AFAIK, you can run X11 on MacOS X, but it does not run X11 out of the box.

I doubt the content of rgb.txt changes very much, so a quick and dirty way would be to include that file with your program. On the other hand, some part of Perl/Tk must be able to handle colors even on Windows and MacOS X. So, maybe call a Tk method to convert a string to a color and check if it fails.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re: Best way to validate a string as a color? by afoken
in thread Best way to validate a string as a color? by pra

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.