Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Code for Perlmonks XML to RSS

by Vautrin (Hermit)
on Mar 30, 2004 at 17:09 UTC ( #341025=note: print w/replies, xml ) Need Help??

in reply to Code for Perlmonks XML to RSS

I was just playing around with your++ script. It's very cool, but I have the following comments / suggestions:

  1. The line:

    die unless $response->is_success;

    Really should be:

    die ("Could not fetch the web page because: " . $response->status_line) unless $response->is_success; die ("Content type not text/xml. It was" . $response->content_type) unless ($response->content_type eq 'text/xml');

    Otherwise you aren't notified why a get() fails, and it allows the user to try parsing a non XML web page -- which leads to some humorous results.

  2. Why is it even necessary to pass in the URL for the newest nodes page? Your script doesn't look like it will work on any page besides the newest nodes page, so doing a shift (@_) for the URL seems useless. Why not just set my $url = ""; and be done with it?
  3. Excellent work. I thoroughly enjoyed it. Also, not to nitpick, but why don't you put

    use strict; use warnings;

    at the top of your script? It runs with no problems under them, and it's good practice (plus I think it's a good idea to help any new monks seeing it to get in the habit of using them).

Good job again!

Want to support the EFF and FSF by buying cool stuff? Click here.

Replies are listed 'Best First'.
Re: Re: Code for Perlmonks XML to RSS
by xdg (Monsignor) on Mar 30, 2004 at 21:02 UTC

    Thanks for the comments. As I said, it was quick and dirty and your suggestions are worthwhile additions. For the record, this was pasted out of a larger script which did have strict and warnings on and was originally set for passing in URL's from the command line, which is why that appears that way. I probably should have cleaned it up further. Certainly, adding strict and warnings even in my example to encourage good practice among others is a great suggestion.


    Code posted by xdg on PerlMonks is public domain. It has no warranties, express or implied. Posted code may not have been tested. Use at your own risk.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://341025]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2022-01-26 23:00 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (70 votes). Check out past polls.