Well here is a simple way to put it into a Tk marquee.

UPDATESet timer to update every 5 minutes.

#!/usr/bin/perl #click on marquee to remove use strict; use LWP::Simple; use Tk; my $text; my $mw = tkinit; $mw->geometry('+20+20'); $mw->overrideredirect(1); my $label = $mw->Label( -textvariable=>\$text, -font=>'courier', -bg=>'green', -bd=>4, -relief=>'ridge' )->pack(-fill=>'both'); getnews(); $mw->repeat(300000,\&getnews); $label->bind('<ButtonRelease>',sub{$mw->destroy}); $mw->repeat(160,[sub{$text=~s/(.)(.*)/$2$1/;}]); MainLoop; ##################################################### sub getnews{ my %ticker = parse_ticker_data( 'http://tickers.bbc.co.uk/tickerdata/story2.dat' ); my @stories; foreach my $story (@{ $ticker{'WORLD'} }) { push @stories, $story->{headline} } $text = join ' - ', @stories; $label->update; return; } ###################################################################### +### sub parse_ticker_data { my $ticker_data_url = $_[0]; my (%ticker, $current_category, @stories_in_this_cat, $last_category +, $last_token, $headline, $url); die "No ticker URL supplied to parse_ticker_data()" if (!$ticker_dat +a_url); # Download the ticker data file from the BBC my $ticker_data = get $ticker_data_url; die "Couldn't retrive ticker data" if (!$ticker_data); #for offline testing #open (FILE,"<story2.dat") or die "Couldn't open: $!"; #my $ticker_data = do {local $/; <FILE>}; #close FILE; # Examine each line in the ticker data file foreach (split /\n/, $ticker_data) { if (/Last update at (\d\d:\d\d)/) { # Extract last updated time $ticker{update_time} = $1 . ' GMT'; $headline = undef; next; } # Set the current category if (/HEADLINE\s (SPORTS|BUSINESS|WORLD|UK|SCI-TECH|TRAVEL|WEATHER|FINANCE)/x) { $current_category = $1; $last_token = 'new'; $headline = undef; next; } my ($token, @data) = split /\s/, $_; my $data = join ' ', @data; # Have we changed categories? If so, then we need to store all the + # stories in the old category in the data structure if ($current_category ne $last_category) { if (@stories_in_this_cat) { my @narrow_scoped = @stories_in_this_cat; $ticker{$last_category} = \@narrow_scoped; @stories_in_this_cat = (); } } if ( ($token eq 'HEADLINE') and ($last_token eq 'STORY') ) { # Starting to parse a new headline. Need to put the old one onto + # the array though. if ($headline) { # don't want headlines like "UK News", see ab +ove push @stories_in_this_cat, { headline => $headline, url => $url }; } $headline = $data; } # Set the URL if ($token eq 'URL') { $url = $data; } # Update for next iteration $last_token = $token; $last_category = $current_category; } # The last category won't be added in the loop, so need to do it # manually. This is nasty, so any improvements would be welcome :-) + $ticker{$current_category} = \@stories_in_this_cat; return %ticker; } ##################################################################

In reply to Re: News alerts using the BBC's news ticker data file by zentara
in thread News alerts using the BBC's news ticker data file by SuperCruncher

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!
  • 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:
    & &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.