Leser: 21
my $stmt = 'INSERT INTO job (' . join(',', keys %{$self}) . ') VALUES (' . join(',', ('?') x keys %{$self}) . ')';
1 2 3 4 5 6 7 8 9 10
# ungetestet my @keys = grep { defined $self->{$_} and $_ ne 'ID' } keys %$self; my $fields = join ',', @keys; my $values = join ',', ('?') x @keys; my $stmt = "INSERT INTO job ($fields) VALUES ($values)"; my $sth = $dbh->prepare($sth); $sth->execute(@$self{@keys});
perl -we 'my %new_hash; my %hash = (foo => "bar", rofl => undef); foreach (keys %hash) {$new_hash{$_} = $hash{$_} if defined $hash{$_}}; print %new_hash '