Liek the title says. Uses LWP::Simple to fetch the ticker.
#!/usr/bin/perl -w
=head1 parse the "Other Users XML Ticker" with C<index> and C<substr>
For real. Probably won't work if the "DTD" changes (not bloody likely
+).
=cut
use strict;
use LWP::Simple;
# other users xml ticker
my $html = get('http://perlmonks.org/index.pl?node_id=15851');
die unless $html;
warn $html;
my $fh = [split "\n", $html];
while(@{$fh}) {
parse_other_users(shift @{$fh});
}
exit;
sub parse_other_users {
my $s = shift;
#<user username="Corion" user_id="5348"></user>
my $nX = index($s,'<user user_id='); # 14
my $iX = index($s,'" username="'); # 12
my $IX = index($s,'">', $iX + 11);
my ($name, $id);
if( $iX >=0 and $nX >=0 ) {
printf '(%s)(%s)(%s)(%s)(%s)(%s)'."\n",
$iX,
$nX,
$IX,
$iX - $nX - 14,
$name = substr($s, $nX + 14 + 1, $iX -$nX - 14 - 1),
$id = substr($s, $iX + 12, $IX - $iX - 12),;
}
return;
}
__END__
<CHATTER><INFO site="http://perlmonks.org" sitename="Perl Monks">Rende
+red by the
Other Users XML Ticker</INFO><user user_id="22308" username="dws"></u
+ser>
<user user_id="83485" username="blakem"></user>
<user user_id="65703" username="rob_au"></user>
<user user_id="108447" username="demerphq"></user>
<user user_id="61798" username="busunsl"></user>
<user user_id="78196" username="lestrrat"></user>
<user user_id="103344" username="Ryszard"></user>
<user user_id="134513" username="metadoktor"></user>
<user user_id="141348" username="Dog and Pony"></user>
<user user_id="53018" username="juo"></user>
<user user_id="12012" username="Malach"></user>
<user user_id="107642" username="podmaster"></user>
<user user_id="103824" username="perl::scribe"></user>
<user user_id="143222" username="gdnew"></user>
<user user_id="134230" username="tmiklas"></user>
<user user_id="105312" username="thepen"></user>
</CHATTER>
(130)(110)(145)(6)(22308)(dws)
(20)(0)(38)(6)(83485)(blakem)
(20)(0)(38)(6)(65703)(rob_au)
(21)(0)(41)(7)(108447)(demerphq)
(20)(0)(39)(6)(61798)(busunsl)
(20)(0)(40)(6)(78196)(lestrrat)
(21)(0)(40)(7)(103344)(Ryszard)
(21)(0)(43)(7)(134513)(metadoktor)
(21)(0)(45)(7)(141348)(Dog and Pony)
(20)(0)(35)(6)(53018)(juo)
(20)(0)(38)(6)(12012)(Malach)
(21)(0)(42)(7)(107642)(podmaster)
(21)(0)(45)(7)(103824)(perl::scribe)
(21)(0)(38)(7)(143222)(gdnew)
(21)(0)(40)(7)(134230)(tmiklas)
(21)(0)(39)(7)(105312)(thepen)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.