in reply to Re: CGI.pm HTML-Generation Methods Considered Useful
in thread CGI.pm HTML-Generation Methods Considered Useful

That reminds me; I forgot to include an evil method for alternating row colors:

my @colors = ( '#dddddd', '#eeeeee' ); $html .= $q->table( { -bgcolor => '#ffffff', -border => 1 }, $q->caption('Status Summary'), # beware beautiful nested maps ahead map { my $k = $_; $q->Tr( { -bgcolor => (push @colors, shift @colors) && $colors[0] }, $q->td( $k ), map { $q->td( $data->{$k}{$_} eq 'bad' ? { -bgcolor => '#ff0000' } : { -bgcolor => '#ffffff' }, $data->{$k}{$_} ) } sort keys %{ $data->{$k} } ) } sort keys %{ $data } );

There is no particularly good reason to do this. After this, it's just for fun. :)

Replies are listed 'Best First'.
Re^3: CGI.pm HTML-Generation Methods Considered Useful
by tachyon (Chancellor) on Jul 10, 2004 at 12:06 UTC

    Surely you meant to map to stylesheet classes? Does anyone still hardcode colors into their code these days? It is 2004 afterall....

    Do you find it vaguely inefficient to use 3000+ lines of code + your 18 to do what <30 lines of code (or one line as a call when you modularise it) will do just as well, faster and in a more transparent maintainable and consistent manner?

    Hmm does that sound biased? OK I admit it. I think CGI.pm has no place in generating HTML in the first place, and don't like the interface. You either love it or you hate it. I have used it. I do hate it. Ovid likes it and so does merlyn. What can I say? They are obviously misguided, or I have no idea what I am talking about. Or perhaps they use what works for them as I use what works for me. Use what works for you. TIMTOWDI.

    cheers

    tachyon

      I use it when I don't have a templating solution nearby, or even in combination with a templating solution. CGI.pm generates shortcuts for common things, like option lists and headers, but also handles the sticky form elements. I don't know of any other as-ubiquitous easy solution for handling sticky form elements.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

      In the real world, I generally only use it when I need a one-off solution to generate static HTML. I wouldn't use it in a live web application, unless it was some internal thing that only saw occasional use.