http://qs321.pair.com?node_id=120803

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

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; }