#!/usr/bin/perl -w # Wait 10 seconds for the first image # How can create the LWP::UserAgent object just once? # bizzach@lookiloo.net my $mw = new MainWindow; my $l = $mw->Label( -text => 'Wbscam', -foreground => 'blue', -font => [qw/-size 100 -slant italic/] ); $mw->repeat(10000 => \&run); $l->pack(); MainLoop; sub run { my $bytes = get_photo(); my $photo_data = encode_base64($bytes); my $photo = $mw->Photo(-data => $photo_data, -format => "jpeg"); $l->configure(-image => $photo); } sub get_photo { my $ua = LWP::UserAgent->new(timeout => 30, keep_alive => 1); my $r = $ua->get('http://fiver.homeunix.com/images/webcam.jpg'); my $content; if ($r->is_success) { $content = $r->content; } return $content; }