Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Sort label

by gryphon (Abbot)
on Jul 17, 2005 at 21:59 UTC ( #475596=note: print w/ replies, xml ) Need Help??


in reply to Sort label

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;


Comment on Re: Sort label
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://475596]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2014-07-30 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (241 votes), past polls