Trihedralguy has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use DBI; use CGI qw/:standard/; use strict; my $cgi = new CGI; print header('text/html'); my $color_sent = $cgi->param('colorselect'); my $id_select = $cgi->param('id_select'); if (!$color_sent && !$id_select) { exit; } $color_sent = substr($color_sent, 1); $id_select = substr($id_select, 1); my $dbh = DBI->connect("DBI:mysql:xxxxxxxxxxx:xxxxxxxxxxxx", "xxxxxxxxxxxxx","xxxxxxxxxxxxxxxxxx"); if ($id_select ne 'esult') { #Update the database. } my $get_all_colors = $dbh->prepare(" SELECT color_code, element_id FROM current_information ORDER BY element_id "); $get_all_colors->execute(); #thezip told me about this #if (exists($hash{$value}) { # ... do something ... } #jporter told me about this #$hash{$key} ||= { }; $hash{$key}{$slot} = 'foo'; my $colorchart{0} ||= { }; my $key = 0; while (my ($color_code, $element_id) = $get_all_colors->fetchrow_array +) { if (exists($hash{{$element_id}) { # ... do something ... } $colorchart{$element_id} = '$color_code'; $key++; } print qq^ <style type="text/css">^; my $counter = 0; while ($key >= $counter) { .b$colorchart{$key}{2} {color: #$colorchart{$key}{1} }; $counter++; } print qq^; </style>^; $counter = 0; while ($key >= $counter) { print qq^<div id="b$element_id" class="btn px"><a href="#"></a></d +iv>^; $counter++; } #this is what I use to have before I wanted to get smart. #while (my ($color_code, $element_id) = $get_all_colors->fetchrow_arra +y) #{ #print qq^<div id="b$element_id" class="btn px" style="background-colo +r:#$color_code"><a href="#"></a></div> #^; #} $dbh->disconnect(); exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Hashes, Arrays, Comparing Values to Elements
by GrandFather (Saint) on Nov 30, 2008 at 04:20 UTC | |
by Trihedralguy (Pilgrim) on Nov 30, 2008 at 05:10 UTC | |
|
Re: Hashes, Arrays, Comparing Values to Elements
by ig (Vicar) on Nov 30, 2008 at 05:46 UTC | |
by Trihedralguy (Pilgrim) on Nov 30, 2008 at 15:16 UTC | |
|
Re: Hashes, Arrays, Comparing Values to Elements
by Your Mother (Archbishop) on Nov 30, 2008 at 22:54 UTC | |
by Trihedralguy (Pilgrim) on Dec 01, 2008 at 00:20 UTC | |
by GrandFather (Saint) on Dec 01, 2008 at 00:32 UTC | |
|