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

Hi! I have an rss parser script for eggdrop (tcl calls for perl) and I wanted to modify it so that not only the very latest news can be printed, but all since the last printed to channel. To do that, I added a do-until cicle, but no matter what I do, it will only run once.
sub pim_print() { ($ize) = @_; if (!($rss{$ize})) { return 0; } ($content) = &download("$rss{$ize}"); if ((!$content)) { return 0; } $rss = new XML::RSS(encoding => 'ISO-8859-2'); eval { $rss->parse($content); }; $x = @{$rss->{items}}; $y=0; do{ $title = "$rss->{items}[$y]->{title}"; $link = "$rss->{items}[$y]->{link}"; $desc = "$rss->{items}[$y]->{description}"; $result = "$title ($link)"; $conv = Text::Iconv->new('UTF-8', 'ISO-8859-2'); $result = &convert($result); $desc = &convert($desc); $link = &convert($link); $izelast = "$ize"."last"; $izedesc = "$ize"."desc"; if (!(&test_last($file{$izelast},"$desc") == 1)) { if ($y==0){ &wr_last($file{$izelast},"$desc"); &wr_last($file{$izedesc},"$desc"); } print "$header{$ize}$y: $result"; $y++; } } until &test_last($file{$izelast},"$desc") == 1; }
Any ideaes?

20050726 Janitored by Corion: Exchanged PRE for CODE tags

Replies are listed 'Best First'.
Re: rss parser
by tlm (Prior) on Jul 26, 2005 at 12:29 UTC

    The simplest explanation is that the test

    &test_last($file{$izelast},"$desc") == 1
    is always true. Did you want do ... while instead perhaps? (Anyway, you can confirm my guess by changing the until line to something like  until $counter++ < 10;, where you have declared my $counter = 0 at the top of the function.) Without seeing more of your code I can't tell whether this is as it should be or not.

    BTW, your code is very hard to read.

    the lowliest monk

Re: rss parser
by merlyn (Sage) on Jul 26, 2005 at 13:02 UTC
Re: rss parser
by davorg (Chancellor) on Jul 26, 2005 at 13:44 UTC

    Looks like something is broken in your "test_last" subroutine and it's returning 1 when you don't expect it to. But as you haven't shown us the code for that subroutine, it's hard to give you any better advice.

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: rss parser
by jeteve (Pilgrim) on Jul 26, 2005 at 12:13 UTC
    Did you tried with parenthesis around your "until" condition ?
    Nice photos of naked perl sources here !
      tried, no difference.