XML::RSS parsing error

Posted:

If you are using the Perl module XML::RSS in the following way:

my $R = XML::RSS->new;
foreach my $url (@urls) {
  my $content = wget($url);
  $R->parse($content);
}

In older versions of the XML::RSS module, this code worked fine. However, if you have upgraded the module recently, you might have noticed the error message:

Modification of non-creatable array value attempted, subscript -1 at /usr/local/lib/perl5/site_perl/5.8.5/XML /RSS.pm line 792.

It is not the feed that has gone rancid on you, but the library. Try instantiating a RSS object within the loop like this:

foreach my $url (@urls) {
  my $content = wget($url);
  my $R = XML::RSS->new;
  eval{$R->parse($content)};
  if ($@) {
    warn("Parse error: $@");
    next;
  }
}

I’ve added some “exception” handling for free in this example so that parse errors don’t blow up your program.

I’m afraid I did not dive into XML::RSS.pm to figure out the problem, but if someone with that knowledge wishes to post below, I’m sure won’t be the only one who welcomes enlightenment.