Ryan Dillinger wrote:
>
> Hello,

Hi Ryan

> I had two scripts that were identical, well almost. I ran the two together,
> but straghtened them out. Anyway I have one here, that when ran say's: Use  of
> uninitialized value in pattern match (m//) at headline.pl line 7 and 10. I
> have  changed differernt things within, nothing worked. It is back to it's
> original state now. Can  someone point out the problem I have with this script
> please? Thanks For your help!
>
> #!/usr/bin/perl
> use warnings;
> use strict;
>
> open LYNX, "lynx -source http://www.perl.com/ |" or die "Can't open lynx: $!";
> $_ = "";

There is no need for this assignment as you change the value again straight
away.

> $_ = <LYNX> until /standard\.def/;

As Mumia pointed out, this line will not complete if there is no 'standard.def'
in the page. Better to:

  while (<LYNX>) {
    last if /standard\.def/;
  }

  die "Unable to find 'standard.def' in Web page" unless defined;

> my $head = <LYNX>;
> $head =~ m|^<A HERF=[^>]+>(.*?)</a>|i;
>
> print "Today's www.perl.com headline: $!\n";

Using HREF instead of HERF and $1 instead of $! should make this work.

This whole thing would be better done using something like LWP::Simple and
HTML::TokeParser (or, as Shawn suggested, HTML::TreeBuilder) like this:

  use LWP::Simple;
  use HTML::TokeParser;

  my $page = get('http://www.perl.com/');

  my $p = HTML::TokeParser->new(\$page) or die "Unable to parse page";

  while (my $anchor = $p->get_tag('a')) {
    my $text = $p->get_trimmed_text('/a');
    print $text, "\n";
  }

which will print the text contents of all the <a> elements in the page.
*However*, looking at the current contents of the page there is no
'standard.def' string and I can't see anything that would be called a headline,
so I can't guess any further how to distinguish the particular element you want
to see. Anyway, HTH.

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to