in reply to HTTP Requests and Threading
G'day carlriz,
Welcome to the monastery.
In the main, this looks like a well-written piece of code. Were you just looking for comments on the code or are you experiencing some difficulties (e.g. something doesn't work as expected, excessive run time, chews up lots of memory, etc.)?
If the 'x50' (in my @URLs = ...) is related to the THREADS constant, then 'x THREADS' would be a better choice.
I'd probably set the timeout value as a constant (near the top of the script) and keep comments relating to that value there. The current comment refers to testing so presumably that's intended to change during the development cycle. Consider the chances of forgetting to search through the script for $ua->timeout(5) and changing it, against the chances of not spotting TIMEOUT => 5, # for testing near the top; you also won't have to search for $ua->timeout(TIMEOUT) (however many times it occurs) as it won't need modification.
Overall, the layout looks very good and is easy to read. I'd aim to keep lines <= 80 characters (others have different preferences: 72 and 78 characters are common). When lines start to get much longer than this, readability suffers. Consider the readability of one of your lines and the suggested alternative following it:
my %query_hash = (action => 'submit or status', name => 'chris', outn +ame => 'chris', 'content-type' => 'application/json');
my %query_hash = ( action => 'submit or status', name => 'chris', outname => 'chris', 'content-type' => 'application/json' );
Finally, of minor importance and I suspect this may be an artefact of your editor, you have a large amount of extraneous whitespace after many of you lines. Because this is wrapping in my browser (and I suspect this will be true for many others), I actually see your intended
######### # Main # #########
as
######### + # Main # + ######### +
There's many examples of that wrapping issue throughout the code you posted.
-- Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: HTTP Requests and Threading
by carlriz (Beadle) on Mar 06, 2014 at 19:43 UTC | |
by BrowserUk (Patriarch) on Mar 06, 2014 at 20:44 UTC | |
by carlriz (Beadle) on Mar 07, 2014 at 16:10 UTC | |
by PerlSufi (Friar) on Mar 06, 2014 at 19:49 UTC |