Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Sort label

by gryphon (Abbot)
on Jul 17, 2005 at 21:59 UTC ( [id://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;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found