eval {} is your friend :)
#!/usr/bin/perl # http://perlmonks.org/?node_id=1201508 use strict; use warnings; my @colors = qw( red green nosuchcolor blue ); my $defaultcolor = 'black'; use Tk; my $mw = MainWindow->new; for my $color ( @colors ) { eval { $mw->Label( -text => $color, -fg => $color )->pack; 1; } // $mw->Label( -text => $color, -fg => $defaultcolor )->pack; } MainLoop;
In reply to Re: Best way to validate a string as a color?
by tybalt89
in thread Best way to validate a string as a color?
by pra
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |