develooper Front page | perl.perl6.language | Postings from September 2005

matching colors (was Stringification, numification, and booleanification of pairs)

Thread Next
From:
Juerd
Date:
September 25, 2005 12:35
Subject:
matching colors (was Stringification, numification, and booleanification of pairs)
Message ID:
20050925193455.GN24163@c4.convolution.nl
Yuval Kogman skribis 2005-09-25 21:34 (+0300):
> > if $color.as(Str) eq '#FF00FF' and "$color" eq "magenta" {
> >   $Ashley++;
> > }
> $color.hex_triplet; # no alpha
> $color.name; # if we have one... or we can try to make one up (#ff0033 is bluish red ;-)

We can do better than equivalence testing for colors. Instead, try to
match. Surely a *smart* match operator really is smart? 

    $color ~~ '#FF00FF'
           ==
    $color ~~ 'magenta' 
           == 
    $color ~~ [ 255, 0, 255 ]


Juerd
-- 
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html 
http://convolution.nl/gajigu_juerd_n.html

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About