go ahead... be a heretic | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
bobf asked me to expand on my scary comment in my original reply. Here goes.
My first beef, 'use warnings;' instead of -w unless you have a good reason to believe your code will run on pre 5.6
a lone declaration, what will $feed be for I wonder?
Whoops, using a global filehandle, and two arg open is not a good habit unless you have reason to believe your code will be run on earlier perls.
Aha, so $feed will be used to store the retreived XML. Cool.
Waitaminute, now we print the contets of $feed to the FH. WTF!?
ok this is all pretty normal, but indirect notation is a bad habit to get into in perl, better to use XML::Parser->new()
Ok, so now we read the data back from the file we just wrote. Of course we have serious issues here, as we havent closed the FH that we wrote to this file with earlier, meaning that the buffer probably isn't flushed and we aren't reading the full contents. Were the filehandle a lexical and properly scoped the filehandle would have automatically closed and flushed as it dropped out of scope. As it is the filehandle wont be closed and flushed until the program does so explicitly or the script terminates.
and yet another waitaminute. Why is $feed being used here? whats going on?!
And now we use the $feed variable as well, but its not clear what it holds yet, presumably a hashref.
$feed appears to be a hashref now. Earlier it was a string. Sigh. and the "no strict 'refs'" is really bad here. Apparently it doesnt do anything, but it might. In fact if hdl_char is called before hdl_start then $feed will equal the original XML content and thus we could be treating the xml response as a var name. No matter how you look at this its bad. Either we have a misleading pragma in the sub that doesnt do anything confusing things, or we have some really nasty stuff happening under the surface.
According to the code that calls this sub, $attribs should probably hold a hashref
Woah! Now its a string. Presumably something like "HASH(0xdeadbeef)"
Id assume that this is just an error outright. Preumably strict will choke on this line. I assume DK never actually got to this point in the call graph
---
demerphq First they ignore you, then they laugh at you, then they fight you, then you win.
In reply to Re: Writing a simple RSS feed 'grabber' with XML::Parser. (detailed review)
by demerphq
|
|