in reply to Best way to validate a string as a color?

Hello pra,

Welcome to the Monastery. What about Term::ANSIColor/Function Interface/colorvalid, sample of code bellow:

#!/usr/bin/perl use strict; use warnings; use feature 'say'; use Term::ANSIColor qw(colorvalid); use Term::ANSIScreen qw/:color :constants/; my $valid = colorvalid ('magenta'); say "Color string is ", $valid ? "valid" : "invalid"; say MAGENTA . "Magenta" . RESET; __END__ $ perl test.pl Color string is valid Magenta

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re^2: Best way to validate a string as a color?
by choroba (Cardinal) on Oct 17, 2017 at 16:38 UTC

      You misspelled "color." So, close though... :P

      perl -MString::Approx=amatch -le 'print "OK" if amatch("color", "colou +r")' OK

        Yes, I know. However, "color", although incorrect, is the spelling used in Perl.