Greetings celliott,
I'm not sure I entirely follow what you're wanting to do, but if I'm understanding you correctly, this might help:
my $data = $dbh->selectall_arrayref(
'SELECT ID, NUM FROM INDEX WHERE ID LIKE F% OR ID LIKE G%',
{ Columns => {} }
);
my %index;
foreach (@{ $data }) {
if ($_->{'ID'} eq 'G') {
$index{$_->{'NUM'}} = -1;
} else {
$index{$_->{'NUM'}} = 1 if (not exists $index{$_->{'NUM'}});
}
}
my @index;
foreach (keys %index) {
push @index, 'F' . $_ if ($index{$_} == 1);
}
print join("\n", @index), "\n";
Instead of dealing with all the bind_param and bind_column stuff, I just selectall_arrayref into a reference, then foreach through that to populate %index. It seems to work for me, but I don't like it. It requires looping twice, which just feels like it would be slow. Plus, there's got to be a way to do this with a couple maps, but apparently I'm not smart enough to figure that out today.
gryphon
Whitepages.com Development Manager (DSMS)
code('Perl') || die;
-
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.
|