joshua-hull / Reddit-Image-Scraper

Perl script to download imaged hosted at imgur.com linked from a subreddit at reddit.com
25 stars 8 forks source link

make code a bit more defensive #10

Closed aggrolite closed 12 years ago

aggrolite commented 12 years ago

Just some changes (I think mostly to the code I wrote) to ensure your script doesn't puke. I just learned recently about how using map in void context is a no-no, as it returns values.

-ensure our variables are defined -wrap json decode in eval -don't use map in void context, use for loop instead -trim trailing whitespace (vim does this automatically for me)

aggrolite commented 12 years ago

Oh, and although the JSON call is set to relaxed, it's best to have of habit of wrapping those in an eval{}, or else your script could crash and you'll get a nasty error message like "error":"malformed JSON string, neither array, object, number, string or atom

joshua-hull commented 12 years ago

Appreciate the work.