Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (5)
    As of 2014-07-14 03:23 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (254 votes), past polls