Posted on 2008-09-17 20:53:01-07 by myan
How to implement a callback function in XML::FeedLite?
Hi there, I tried to implement a call back function using a infinite loop (while(1)) and the fetch method in XML::FeedLite. The following is the structure of my code,
#!/usr/bin/perl use strict; use XML::FeedLite; my $url = 'http://finance.google.com/finance?morenews=10&rating=1&q=NYSE:AGM&output=rss'; my $xfl = XML::FeedLite->new(); while(1) { open (FIL, ">test000.xml"); FIL->autoflush(1); $xfl->fetch({$url => sub{ my ($data,$html) = @_; print FIL $data; print "KKKKKK\n"; #used to check the callback frequency. } }); close FIL; }
The callback subroutine (the sub{...} within fetch method) should be called only when the feed data changes, but instead, the callback sub gets called quite frequently, which means it is not a callback. Can anyone help? Thanks a lot in advance! Min
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.