beowulf has asked for the wisdom of the Perl Monks concerning the following question:

I'm having a problem with the following code. It's supposed to give a snippet of HTML that displays the an image that's on a remote site, the name of which changes on a daily basis. The problem is, it dosen't print any thing.
use LWP::Simple; use CGI qw(:standard escapeHTML); { my %cache = (Time => 0, Data => ""); my $comicsdata = { Dilbert => { Page => "http://dilbert.com" , Regex => qr[(/comics/dilbert/archive/images/dilbert\d+.gif)] , Base => "http://dilbert.com" } }; sub get_data { my $out_comics = ""; my $name = ""; foreach $name (keys %$comicsdata) { my $page = get("$$comicsdata{$name}{Page}"); my $regex = $$comicsdata{$name}{Regex}; my @comics = ($page =~ m/$regex/g); my $base = $$comicsdata{$name}{Base}; @comics = map { $base . $_ } @comics; $out_comics .= $name . a({-href=>$page}, map { img({-src=> $_}) +} @comics); } $cache{Time} = time; return($cache{Data} = $out_comics); } } print get_data;
Life? What's a life?

Replies are listed 'Best First'.
Re: Help!!!!!!!!
by dws (Chancellor) on Feb 22, 2001 at 04:19 UTC
    Here's a hint:

    What does $page contain when the script uses it to make a link?

    Extra credit: how could you have found this yourself with two judiciously-placed print statements?

      I guess I was just being forgetful when I was trying to figure out what was wrong.
      Life? What's a life?
Re: Help!!!!!!!!
by yakko (Friar) on Feb 22, 2001 at 04:05 UTC
    This has already been solved. Have a look here for 2 solutions. :o)

    --
    Me spell chucker work grate. Need grandma chicken.

Re: Help!!!!!!!!
by aardvark (Pilgrim) on Feb 22, 2001 at 04:25 UTC
    You may also want to check out an article in the Perl Journal ( Summer 2000 ) which describes how to build TkComics, a Perl/TK web client. You can use it to view all kinds of comics.

    http://www.tpj.com/issues/vol5_2/tpj0502-0010.html

    Get Strong Together!!
Re: Help!!!!!!!!
by beowulf (Scribe) on Feb 22, 2001 at 23:30 UTC
    Thanks y'all
    Life? What's a life?
Re: Broken Dilbert archive script using LWP::Simple
by mazingerz (Initiate) on Jul 06, 2001 at 00:06 UTC
    I'm working on the same problem for my wife: pull down the daily Monty strip.

    I'm trying a paired down version of code (found here) and then altered to send it to her inbox. Thing is, the script only works about 1/5th of the time. The other four times it delievers nothing, or an old image.

    I'm not sure if it's because the regexp I'm doing is off, or if the site has a way of knowing I'm doing an image pull like this.

    At any rate, I'm hoping to get it solved today. I'm working towards building a search agent in perl, and this is one of my first steps.

    Here's the code I'm using:
    #! /usr/bin/perl -w #use LWP::Simple; #$url = "http://www.unitedmedia.com/comics/monty/"; #$url = get($url); #$url =~ /<img src=\"\/comics\/monty\/archive\/images\/(monty\d+\.gif) +\"/; #getstore("http://www.unitedmedia.com/comics/monty/archive/images/$1", +"../$1"); #$url = "http://www.unitedmedia.com/comics/monty/archive/images/$1"; #print $url; #send_mail('emailaddy@here.com', 'sender@here.com', 'Your comic', $url +); # #sub send_mail { # my($to, $from, $subject, $body)=@_; # my $sendmail="/usr/lib/sendmail -t"; # open (MAIL, "|$sendmail") || die "Can't start sendmail: $!"; # print MAIL<<END_OF_HEADER; #From: $from; #To: $to; #Subject: $subject; # #END_OF_HEADER # foreach ($url) { # print MAIL "$_\n"; # } # close(MAIL); #}