Sibling monks, I want to take a slice out of a hash
%g by using an array of keys
@cols. so I do
my @vals = @g{@cols};. So far so good. BUT, I don't know what's in
%g - it may have defined values for all fields, or it may not. What I want in
@vals is the appropriate value from
%g,
or, if that value is not defined, I want some kind of placeholder, preferably
undef but
0 or whatever wd be fine. I just need
something, because when I've done my slicing I feed it to an SQL query thus:
my $placeholders = '?,' x @cols;
chop $placeholders;
my $cols = join ',', @cols;
my $sth = $dbh->prepare("INSERT INTO venue ($cols) VALUES ($placeholde
+rs)") or die $dbh->errstr;
$sth->execute(@vals);
So my question is (A) can I force a hash slice to have an element for every key I feed it? or (B) is there some other cute way to do what I want? Thanks, all.
§
George Sherston
2001-12-11 Edit by Corion : Fixed a </CODE> tag
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.