Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

zdog's scratchpad

by zdog (Priest)
on Jun 02, 2004 at 01:50 UTC ( [id://358978] : scratchpad . print w/replies, xml ) Need Help??

PROPOSAL: Most contraversial nodes

This is something I've been thinking about for a while now and spoken to vroom about on a number of occasions. I figured it was time to stop talking and finally do something. Here is the preliminary code for obtaining the data:

my $dbh = $DB->getDatabaseHandle(); my $nodeids = $dbh->selectcol_arrayref("SELECT DISTINCT vote_id FROM v +ote"); my $uph = $dbh->prepare("SELECT COUNT(*) FROM vote WHERE vote_id=? AND + weight > 0"); my $dnh = $dbh->prepare("SELECT COUNT(*) FROM vote WHERE vote_id=? AND + weight < 0"); my @cnodes = (); NODEID: while ( @$nodeids ) { for ( 1 .. 100 ) { if ( my $nodeid = shift @nodeids ) { $uph->execute( $nodeid ); $dnh->execute( $nodeid ); my ($upvotes) = $uph->fetchrow_array; my ($downvotes) = $dnh->fetchrow_array; push @cnodes, [ $nodeid, ( $upvotes < $downvotes ) ? $upvotes : $downvotes ]; } else { last NODEID; } } trim( \@cnodes ); } trim( \@cnodes ); # display @cnodes ############### sub trim { my ( $cnodes ) = @_; @$cnodes = sort { $a->[1] <=> $b->[1] } @$cnodes; shift @$cnodes while @$cnodes > 30; }

All this is untested in any way, shape, or form. I'm not even sure that all of it is Perl. This is a work in progress. All comments, questions, and suggestions are welcome.

Just some nodes I want to take a look at later on:

converting Time::HiRes
Re: join doesn't seem to insert separators
Global variable vs passing variable from sub to sub
Automating File Rotation
Re: Is there an equivalent $. for lists or arrays in map or foreach? (mapcar!)
What the heck does $|++; do?
Discover a package global's symbol name given a reference
digitally sign XML Document
How can I compare two directories and copy over files missing from one to another?