Thank you Bill. Can I ask (trying to understand, reading the docs and lama book). My understanding is that Keys is the $url and the Value is the title which in my presumption is stored in $links of $links{$url} = $1; I don't understand the $1. Confused here?? how are the keys and values passed to the %links, are both keys & values stored in $1.
If so then is it then possible for other criteria such as $links{$url} = ''; if ($content =~ /<whatever[^>]*>\s*(.*)\s*<\/whatever>/i) { $links{$url} = $2; Any help is appreciated. Malcolm ----- Original Message ----- From: "$Bill Luebkert" <[EMAIL PROTECTED]> To: "Malcolm Debono" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Thursday, February 13, 2003 1:31 AM Subject: Re: help reading file url & loop > Malcolm Debono wrote: > > Hello, > > Can someone please help. > > > > I am trying to get my script to read url's from a file and loop through. I > > can run the script from a form reading the > > my $url = param('url'); (but it will take to long). The code below will > > loop but it doesn't seem to get the url and read the title. I am not very > > experienced so please explain as simple as possible. > > > This should take care of reading the file, retrieving the URLs found > in the file and printing URL/Title to file and browser. Not sure what else > you wanted to do. > > use strict; > > print "Content-type: text/html\n\n"; > > my $lockit = 0; # change to 1 for file locking leave as 0 on windows > > # Absolute path to extract.dat file: > my $outfile = "/Inetpub/wwwroot/cgi-bin/extracthtml/extract.dat"; > > # Absolute path to list.dat file: > my $infile = "/Inetpub/wwwroot/cgi-bin/extracthtml/list.dat"; > > my %links = (); # store URLs and assoc titles > > open PAGE, "<$infile" or die "Can't open $infile: $!"; > while (<PAGE>) { > chomp; > next if not /http/i; > &getinfo ($_); > } > close PAGE; > > print "<html><head><title>URLs and Titles</title></head>\n"; > > # save URLs and titles to file and output to browser > > open OUT, ">>$outfile" or die "Open >>$outfile: $!"; > flock (OUT, 2) if $lockit; > foreach my $url (keys %links) { > > print OUT "$url\n"; > print OUT "$links{$url}\n"; > print OUT "------------------\n"; > print "<BR><BR><B>URL: $url</B>\n"; > print "<BR><B>Title: "; > if ($links{$url}) { > print "$links{$url}"; > } else { > print qq{<font color="#FF0000">No Title on Page</font>}; > } > print "</B>\n"; > } > close OUT; > > exit; > > #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > > sub getinfo { > my $url = shift; > use LWP::Simple 'get'; > > my $content = get ($url); > return 0 if not $content; > > $links{$url} = ''; > if ($content =~ /<title[^>]*>\s*(.*)\s*<\/title>/i) { > $links{$url} = $1; > } > > } > > #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > > sub dienice { > my $msg = @_; > > print "<h2>Error</h2>\n"; > print $msg; > exit; > > } > > __END__ > > -- > ,-/- __ _ _ $Bill Luebkert ICQ=162126130 > (_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED] > / ) /--< o // // http://dbecoll.tripod.com/ (Free site for Perl) > -/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/ > > > _______________________________________________ > Perl-Win32-Users mailing list > [EMAIL PROTECTED] > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > > _______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs