Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical


by ybiC (Prior)
on May 05, 2002 at 16:23 UTC ( #164149=sourcecode: print w/replies, xml ) Need Help??
Category: PerlMonks Related Scripts
Author/Contact Info ybiC

A Perl extension to check PM experience points before a given PerlMonk reaches 'level vroom'.   Handy for monks of the Saint(10)ly persuasion.   Works fine as is, but substantial changes are in the works.

You can peruse all the supporting files initially generated by h2xs here, plus there's a tarball of the whole shebang.

(as this is my first serious-to-completion-of-working-code module writing effort, I'd particularly welcome any and all criticism, complaints, rotton fruit, or even constructive suggestions)

package Xp2v;

use strict;
use Carp;

require Exporter;
require AutoLoader;
require Tie::IxHash;
require LWP::UserAgent;
require HTML::TokeParser;

@ISA = qw(Exporter AutoLoader);
# Items to export into callers namespace by default. Note: do not expo
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
@EXPORT    = qw();
@EXPORT_OK = qw(&fNp);
$VERSION   = 0.03;

# Preloaded methods go here.
# Autoload methods go after =cut, and are processed by the autosplit p

sub fNp{
  tie my %param, 'Tie::IxHash';
  %param = (
    monk1 => shift(@_),
    monkB => shift(@_),
    proxy => shift(@_),
    site  => '',
    agent => "Xp2v/$VERSION",
  return(0, 'Two monknicks must be specified')
    unless $param{monk1} && $param{monkB};

  tie my %url, 'Tie::IxHash';
  %url = (
    monk1 => "$param{site}$param{monk1}",
    monkB => "$param{site}$param{monkB}",

  my $xp;
  my @xp;
  for my $value (values %url) {
    my $content;
    my $ua = new LWP::UserAgent;
    $ua->proxy(http => $param{proxy}) if $param{proxy};
    my $url = new URI($value);
    my $req = new HTTP::Request "GET" => ($url);
    my $res = $ua->request($req);
    if ($res->is_success) {
      $content = $res->content;
    else {
      return(0, $res->message);

    my $pb    = HTML::TokeParser->new(\$content);
    my $regex = '^\d+$';
    TAG: while($pb->get_tag('b', '/b')){
      my $tb = $pb->get_text();
      $xp = $tb;
      last TAG if $tb =~ /$regex/;
    return(0, 'xp not parsed') unless $xp =~ /$regex/;
    push @xp, $xp;
  my $xp1 = $xp[1];
  my $xpB = $xp[0];
  return(1, $xp1-$xpB);

return 1;

=head1 NAME

Xp2v - Perl extension to check xp before a PerlMonk reaches 'level vro


 #!/usr/bin/perl -w
 use strict;
 use Xp2v qw(fNp);

 my @xp2v = fNp( my_monk_nick, vroom,);
 my $success = $xp2v[0];
 if($success == 1){
   my $xp2v = $xp2v[1];
   print "my_monk_nick has $xp2v xp to level vroom\n";
   my $err = $xp2v[1];
   print "\n", $err, "\n";


Provide a procedural interface to determine how many experience points separate two specified monks.

Fetch respective homenodes, parse for xp's, subtract and return diff.
Return LWP::UserAgent error message if problem fetching.



=head1 OPTIONS

 proxy (http://proxyhost.tld:port_num)

=head1 AUTHOR



 $xp not defined if check thepen's xp.
 Works fine for NodeReaper, so not as simple as negative rep.

 Please read CAVEATS for other potential issues of note.

=head1 SEE ALSO

perl(1), Tie::IxHash(3), LWP::UserAgent(3), HTML::TokeParser(3).


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://164149]
[1nickt]: But I removed it when I travelled to somewhere more, er ... red. Why? Because I thought how stupid I would feel ...
[karlgoethebier]: 1nickt: I fear not. Perhaps enough for Europe...
[1nickt]: ... if I involved my wife (or myself) in an altercation over a slogan.
[1nickt]: I will not convince anyone who disagrees with me, with a sticker. And I don;t need to advertise my thoughts, really.
[Discipulus]: ++1nickt but what about: "out immigrants! just redskins!"
[1nickt]: I know what I believe and whether I have integrity. My actions will speak more.
[karlgoethebier]: choroba Nothing unclever in my sig. And remember: Beeing too clever is a bad mistake ;-)
[1nickt]: This is not to suggest that Karl should remove his slogan. Just thoughts of mine... Trust me I believe I am very much more radical than most, and if I had a slogan for every gross injustice in my sig, there would be no more bytes!
Discipulus redskins .. well native american..
[1nickt]: So if I was to offer any editorial advice it would be to (1) make it endure time passing (2) make it positive (3) make it about you and your beliefs

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2017-06-22 12:06 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (519 votes). Check out past polls.