Ask a Question related to PERL Modules, Design and Development.
-
DVH #1
Nested loops?
Hi,
I've been adapting a script which parses HTML and creates an RSS feed
([url]http://www.perl.com/lpt/a/2001/11/15/creatingrss.html[/url]).
Now I want to get each URL it parses, then parse the HTML it finds there and
copy part of it to the <description> part of the XML.
I'd like to nest one 'while' loop inside another, as shown below, but it
only picks up the first URL and the trimmed_text, then gives up. Any
pointers would be welcome.
=======================================
my ($tag, $headline, $url, $description );
while ( $tag = $stream->get_tag("a") ) {
if ($tag->[1]{class} and $tag->[1]{class} eq "docSel-titleLink") {
$url = $tag->[1]{href} || "--";
$headline = $stream->get_trimmed_text('/a');
$url = 'http://europa.eu.int/rapid/'.$url;
$url =~ s/\s//g;
$url =~ s/&/&/g;
my $text = get( $url ) or die $!;
my $second_stream = HTML::TokeParser->new( \$text ) or die $!;
while ( $tag = $second_stream->get_tag("b") ) {
$description = $second_stream->get_trimmed_text('/b'); }
$rss->add_item( title => $headline, link => $url, description =>
$description );
=======================================
DVH Guest
-
HTML::Template arbitraryily nested recursive loops
Can anyone suggest a way to display an arbitrarily deep nested loop structure using HTML::Template? Below is what I've tried. I have a data... -
Possible Bug w/ nested loops and queries
May have found a possible bug... can someone please verify? In a database I have two tables, temp1 and temp2 These tables can contain anything,... -
Using 'my' within nested loops
I am curious about the amount of overhead created with the first example below as compared to the second example below: Example 1: my $this;... -
[PHP] nested for loops
your syntax is correct, just need to change for ($j=0: $j < 5; $j++) to for ($j=0; $j < 5; $j++) Anyone ever do a nested for loop? $i =0; $j... -
nested for loops
Anyone ever do a nested for loop? $i =0; $j =0; for ($x=0; $x < 50; $x++){ echo ("1 to 50"); for ($j=0: $j < 5; $j++) { echo ("less than... -
usenet@DavidFilmer.com #2
Re: Nested loops?
DVH wrote:
Perl never "gives up." What do you mean? Do you mean your script dies> it only picks up the first URL and the trimmed_text, then gives up.
on this line:
What is the error message it returns?> my $text = get( $url ) or die $!;
usenet@DavidFilmer.com Guest
-
DVH #3
Re: Tokeparser - Nested loops?
<usenet@DavidFilmer.com> wrote in message
news:1131869610.991717.228470@g14g2000cwa.googlegr oups.com...No error message. It correctly returns the first URL and the trimmed text,> DVH wrote:>> > it only picks up the first URL and the trimmed_text, then gives up.
> Perl never "gives up." What do you mean? Do you mean your script dies
> on this line:
>>> > my $text = get( $url ) or die $!;
> What is the error message it returns?
>
and pushes them into 'link' and 'title'. But until I started trying to get a
second 'while' loop working, it returned twelve URLs and the corresponding
trimmed_text, instead of only one as it does now.
Clearly it finds the first conditions of the loop true, but the remaining
ones false. I'm not sure why?
DVH Guest
-
Eric Bohlman #4
Re: Nested loops?
"DVH" <dvh@vhvhvhvhvhvhvh.com> wrote in
news:dl5p2m$1fj$1@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com:
Please show us your actual code, cut-and-pasted rather than retyped (the> my ($tag, $headline, $url, $description );
>
> while ( $tag = $stream->get_tag("a") ) {
>
> if ($tag->[1]{class} and $tag->[1]{class} eq "docSel-titleLink") {
>
> $url = $tag->[1]{href} || "--";
>
> $headline = $stream->get_trimmed_text('/a');
>
> $url = 'http://europa.eu.int/rapid/'.$url;
>
> $url =~ s/\s//g;
>
> $url =~ s/&/&/g;
>
> my $text = get( $url ) or die $!;
>
> my $second_stream = HTML::TokeParser->new( \$text ) or die $!;
>
> while ( $tag = $second_stream->get_tag("b") ) {
>
> $description = $second_stream->get_trimmed_text('/b'); }
>
> $rss->add_item( title => $headline, link => $url, description =>
> $description );
code you typed has three opening braces and only one closing brace, so
we're left to guess how your loops are nested). Please use a reasonable
indentation style and don't double-space it.
Eric Bohlman Guest
-
Unregistered #5
Re: Nested loops?
Nested while loops do not work in Perl...its really amazing that you dnt know it untill you face that problem
Unregistered Guest



Reply With Quote

