Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
package Xp2v; use strict; use Carp; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); 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 +rt # 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 +rogram. sub fNp{ tie my %param, 'Tie::IxHash'; %param = ( monk1 => shift(@_), monkB => shift(@_), proxy => shift(@_), site => 'http://perlmonks.org/index.pl?node=', 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->agent($param{browser}); $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; __END__ =head1 NAME Xp2v - Perl extension to check xp before a PerlMonk reaches 'level vro +om'. =head1 SYNOPSIS #!/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"; }else{ my $err = $xp2v[1]; print "\n", $err, "\n"; } =head1 DESCRIPTION Provide a procedural interface to determine how many PerlMonks.org 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 REQUIRED ARGUMENTS first_monk_nick second_monk_nick =head1 OPTIONS proxy (http://proxyhost.tld:port_num) =head1 AUTHOR ybiC =head1 KNOWN BUGS $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). =cut

In reply to (code) Xp2v.pm by ybiC

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
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 studying the Monastery: (8)
As of 2024-03-28 11:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found