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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl -w use strict; use Tk; use Socket; use IO::Handle; use HTML::Entities; my (%stories, @bs, @binds, $mw, $value, $scale, $scaled, $frame, $timer, $pid, $prog); $prog = q(use Socket; $inet = inet_aton "www.slashdot.org"; $proto = getprotobyname "tcp"; socket(S, PF_INET, SOCK_STREAM, $proto) || exit; if(connect(S, pack "SnA4x8", 2, 80, $inet)) { select S; $| = 1; print "GET /slashdot.rdf HTTP/1.0\n\n"; select STDOUT; $| = 1; while (<S>) { $title = $1 if /\<title\>(.*)\<\/title\>/; $url = $1 if /\<link\>(.*)\<\/link\>/; if (/<\/item>/) { print length($title),":",$title,$url,"\n"; } } close S; close STDOUT; }); @binds = ('<Enter>', '<Motion>', '<Leave>', '<1>', '<B1-Motion>', '<B1-Leave>', '<B1-Enter>', '<ButtonRelease-1>', '<2>', '<B2-Motion>', '<B2-Leave>', '<B2-Enter>', '<ButtonRelease-2>'); $scaled = 1; $mw = MainWindow->new; $mw->resizable(0, 0); $mw->configure(-title => 'Slashdot Headline Grabber'); $mw->repeat(1800000, \&Get); $frame = $mw->Frame(-relief => 'ridge', -borderwidth => 2); @bs = ($frame->Button(-text => 'Get', -activebackground => '#43ce80', -command => \&Get), $frame->Button(-text => 'Clear', -activebackground => '#43ce80', -command => \&Cancel), $frame->Button(-text => 'Exit', -activebackground => '#43ce80', -command => \&Leave) ); $scale = $mw-> Scale(-showvalue => 0, -relief => 'flat', -sliderrelief => 'flat', -background => '#43ce80', -borderwidth => 0, -troughcolor => 'white', -orient => 'horizontal', ); map($mw->bind("Tk::Scale", $_, ""), @binds); $frame->pack(-anchor => 'n', -expand => 1, -fill => 'x'); map($_->pack(-side => 'left', -expand => 1, -fill => 'x'), @bs); $scale->pack(-anchor => 'nw', -expand => 0); MainLoop; sub Scale () { $_ = $scale->get(); if ($_ <= 0) {$scaled= 1} if ($_ >= 100) {$scaled = -1} $scale->set($_ + $scaled); } sub Get () { &Cancel; $timer = $mw->repeat(9, \&Scale); $pid = open (A, "perl -e '$prog'|"); $mw->fileevent(\*A, 'readable', [\&Insertt]); } sub Cancel () { &Abort; &Clear; } sub Abort () { if ($pid) { kill 9, $pid; close A; $mw->fileevent(\*A, 'readable', ''); $pid = 0; $timer->cancel(); $scale->set(0); $timer = 0; } } sub Browser ($) { if (-l "$ENV{'HOME'}/.netscape/lock") { system(qq/netscape -remote 'openURL($_[0], new-window)' &/); } else { system(qq/netscape $_[0] &/); } } sub Clear () { map($_->[1]->destroy, values %stories); %stories = (); } sub Leave () { &Abort; exit; } sub Insertt () { my ($button, $title, $url); $_ = A->getline; if (defined $_) { chop; if(!/^(\d+):/ || !$1 || !/$1:(.{$1})(.+)/ ) {return} ($title, $url) = ($1, $2); decode_entities($title); $button = $mw->Radiobutton(-anchor => 'w', -indicator => 0, -relief => 'groove', -activebackground => '#43ce80', -text => $title, -value => $title, -variable => \$value, -command => sub { $stories{$value}[1] -> flash(); Browser($stories{$value}[0]); $stories{$value}[1] -> deselect(); }) ->pack(-fill => 'both', -expand => 1); $stories{$title} = [$url, $button]; } else {&Abort} }

In reply to Slashdot Headline Grabber for *nix by czyrda

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 chilling in the Monastery: (2)
As of 2024-04-20 03:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found