in reply to RSS Parsing not working on new machine

OK, so, playing around with my test version, I've discovered that including Use Try; breaks it in exactly the way I'm seeing, regardless of whether or not there are any try/catch blocks. If I remove Try from my script, it works (but will be more fragile), except that it's still breaking on some feeds, always on lines that contain CDATA, but they all include CDATA blocks, and these aren't the first in the feeds, so it's not going to be that obvious:

-- Feed is broken -- End tag mismatch (itunes:subtitle != content:encoded) [Ln: 735, Col: 2 +93548366282188] Line 734 78 <itunes:subtitle><![CDATA[It is the QUESTIONS +EPISODE!]]></itunes:subtitle>

If I run it several times, the same feeds are consistently breaking on the same line, so something weird is still happening.

Replies are listed 'Best First'.
Re^2: RSS Parsing not working on new machine
by Corion (Patriarch) on Apr 15, 2025 at 17:40 UTC

    Depending on your Perl version, native try { ... } catch  { ... } finally { ... } blocks may already be available. Perl 5.34 introduced try ... catch. So maybe you want to use that over Try.

    Alternatively, there is the more weathered Try::Tiny, which also gives you a try/catch pair.

      It looks like the builtin try is getting depreciated, so I'm not keen on using it long term. Having said that, swapping in use experimental 'try'; works (for most feeds; see above). Swapping in Try::Tiny gives me this new error:

      syntax error at /home/ross/scripts/podcasts/podcasts.pl line 233, near + ") {" Execution of /home/ross/scripts/podcasts/podcasts.pl aborted due to co +mpilation errors.

      This is the section it's complaining about:

      try { $curl->pushopt(CURLOPT_HTTPHEADER, [$ua_string]); $curl->setopt(CURLOPT_PROGRESSFUNCTION, \&no_progress); $curl->setopt(CURLOPT_NOPROGRESS, 0); $curl->setopt(CURLOPT_FOLLOWLOCATION, 1); $curl->setopt(CURLOPT_CONNECT_ONLY, 0); $curl->setopt(CURLOPT_URL, $feedsrc); $curl->setopt(CURLOPT_WRITEDATA, \$feed); $curl->perform(); } catch { $broken = 1; #putting next in here complains that it's exi +ting a subroutine } if (!defined($feed)) { # <--- Line 233 $broken = 2; }

      I can't see an error there, and it doesn't throw one without Try::Tiny, so that seems pretty weird.

      EDIT

      OK, I figured that out. The Try::Tiny try/catch blocks need a closing semicolon. So now I have a robust try that won't go away in future versions of perl, and isn't somehow messing up all the feeds, but some are still getting messed up in ways I don't understand.

        It looks like the builtin try is getting depreciated

        The word is deprecated. But what gives you that idea? It just stopped being experimental in the latest version (5.40), so why do you think it's going to be deprecated in the next one?

        a try{}catch{}; block needs a semicolon at the end!. It's not a block I guess. FYI, I have tried all of these and I ended up with plain old eval(). I can not be sure of the reasons now. But surely I went this routine a few times.