in reply to Re: Re: Perl OOP variables
in thread Perl OOP variables
You can call it %Reputation if you want.use Tie::DBI; tie %db,Tie::DBI,{db => "mysql:Perlmonks", table => "Reputation", key => "nodeid", user => $def_dbuser, password => $def_dbpw, CLOBBER => 3};
Then, you can access the table directly and intuitively.
This sample from my rewrite of luke_repwalker.pl, which I have tweaked to use Tie::DBI.# # Find all the new, deleted and changed entries # And find the longest title # calculate min and max reputations and total # Just want to make one pass through all of the list # for (keys %db) { my $type = $db{$_}->{type}; next if $type eq 'X'; push (@newnodes, $_) if $type eq 'N'; push (@deletednodes, $_) if $type eq 'D'; push (@changednodes, $_) if $type eq 'C'; $longest_title = max ($longest_title, length ($db{$_}->{title})) +; $total += $db{$_}->{reputation}; $repmax = max ($repmax, $db{$_}->{reputation}); $repmin = min ($repmin, $db{$_}->{reputation}); }
|
|---|