Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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?
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2025-03-24 13:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When you first encountered Perl, which feature amazed you the most?










    Results (64 votes). Check out past polls.

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.