Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

(jeffa) 2Re: Simplicity vs. Doing It Right

by jeffa (Bishop)
on Oct 13, 2002 at 18:56 UTC ( [id://204932]=note: print w/replies, xml ) Need Help??


in reply to Re: Simplicity vs. Doing It Right
in thread Simplicity vs. Doing It Right

You must be referring to the code over at Re: Re: Hex color degrader. I decided to take the 'Pepsi Challenge'™, and - not to best you - i thought it would be benificial for the community to post a very similar solution that used CGI.pm's methods: (refer to said link for orginal code)
print start_table, Tr(td(' '), th[@colors]); for my $scale ( -5 .. +5 ) { print Tr(td($scale/10)), Tr( map { td{bgcolor=>'#'.$_},$_ } map { Dlighken($_, $scale/10) } @colors ) ; } print end_table;
Thanks to your existing code, it only took me about 5 minutes or so to port - however, when one considers how much total time that i have spent learning how to massage CGI.pm, i feel that your argument here bears even more weight. I liken this to playing a musical instrument - the time one spends practicing different scales, licks, chops, etc. will, in the long run, improve one's improv skills. But, when on the spot ... it's best to stick with what one knows right now.

Cool code, BTW. :)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: (jeffa) 2Re: Simplicity vs. Doing It Right
by BrowserUk (Patriarch) on Oct 13, 2002 at 21:50 UTC

    In my defense, I was trying to be a little more CGI.pm about it and adopt the 'poetry mode'. With another hour of giggling I finally cracked what I was so close to before.

    This produces the same out put as my original above and uses but a single print statement, in deference to all those post I've seen saying "You don't want all them print statements, use CGI.pm" ;^).

    Whether this is better or worse than my original or yours I'll leave it to the reader to make their own conclusions.

    #! perl -sw use strict; use CGI qw/:standard *table/; use CGI::pretty; sub Dlighken { return sprintf '%02x'x3, map{ ($_ *= 1+$_[1]) > 0xff ? 0xff : $_ } map hex, unpack 'A2'x3, $_[0]; } my @colors = qw/800000 808000 008000 008080 000080 808080 c0c0c0/; print table( Tr( th(' '), th([@colors]) ), map{ my $scale = $_/10; Tr( td($_), map{ td({bgcolor=>"$_"},[$_]) } map{ Dlighken($_, $scale) } @colors ) }( -5 .. +5 ) ) ; __END__

    Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://204932]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-23 20:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found