Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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 taking refuge in the Monastery: (12)
As of 2015-07-31 16:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (279 votes), past polls