I would like to do something like
push(@ary,\%hash) instead of
@ary = (\%hash); so that
all the values will be in @ary.
I cannot get it to work. Any idears???
Soren
#!/usr/local/bin/perl -wT
use strict;
use HTML::Template;
use CGI;
use DBI;
my $cgi = new CGI;
use constant TMPL_FILE => "$ENV{DOCUMENT_ROOT}/um/templates/search.tmp
+l";
my $tmpl = new HTML::Template( filename => TMPL_FILE );
my $search = $cgi->param("search");
my $rapport = $cgi->param("rapport");
my $dbh = DBI->connect("um","","","mysql") ||
die "Could not connect: $DBI::errstr\n";
my %attr = ( dbi_fetchall_arrayref_attr => {} );
my @selector;
if ($rapport eq undef) {
@selector = qw(fornavn efternavn cpr adresse zip city telefon mobil g_
+afsluttet bemyndigelse_til tjenestested id pic godkendelse_done);
} else {
@selector = qw(fornavn efternavn cpr bemyndigelse_til tjenestested god
+kendelse_done g_afsluttet);
}
my @s = split(/ /, $search);
my $row = $dbh->selectall_arrayref('select '. join(',' , @selector)."
+from people
where ((fornavn like '%$s[0]%') and (efternavn like '%$s[$#s]%')) or (
+fornavn LIKE '%$search%') or (efternavn LIKE '%$search%') or (cpr LIK
+E '%$search%')",\ %attr);
my %hash;
my @ary = @$row;
my ($i, $k, $v, $date);
for ($i=0; $i<=$#ary; $i++) {
%hash = %{$ary[$i]};
$date = con_date($hash{"g_afsluttet"});
$hash{"g_afsluttet"} = $date;
}
HELP NEEDED HERE :o)
@ary = (\%hash);
HELP NEEDED HERE :o)
#--------Farven findes start -----------------
my $color;
if ($hash{"godkendelse_done"} =~ '1') {
$color = 'white';
} else {
$color = 'red';
}
#--------Farven findes slut ------------------
#----------Data slettes start ----------------
if ($rapport ne undef) {
delete $hash{"g_afsluttet"};
}
delete $hash{"godkendelse_done"};
#----------Data slettes slut -----------------
$tmpl->param( search => $search, rapport => $rapport , row => \@ary ,
+color => $color );
print "Content-type: text/html\n\n",
$tmpl->output;
$dbh->disconnect;
sub con_date {
my ($org_date) = @_;
my ($yyyy, $mm, $dd) = ($org_date =~ /(\d+)-(\d+)-(\d+)/);
my $ret = sprintf ("%02d-%02d-%04d", $dd, $mm, $yyyy);
return $ret;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.