Update: The code is very different now
compared to when I first wrote this reply, so I'll just keep
the parts that I think might still be relevant (and ++ the
current version!)</update>
I agree that this provides a nice case study for simplifying
streamlining web interaction, but every time I see more than two levels
of indentation for nested "if (okay) ... else ..." blocks,
I wince a little. I think it would be more readable (as
Perl code, at least) if you did it this way:
...
my $baseURL = "http://www1.myvodafone.com.au";
my $res;
logmsg("Requesting homepage ...");
$res = $ua->request(new HTTP::Request(GET=>$baseURL));
$res->is_success or giveUp($res->status_line);
logmsg("Logging in...");
$res = $ua->request(POST "$baseURL/userpages", ... );
$res->is_success or giveUp($res->status_line);
logmsg("Requesting SMS form...");
$res = $ua->request(new HTTP::Request(GET=>"$baseURL/userpages/web2txt
+.fcgi"));
$res->is_success or giveUp($res->status_line);
logmsg("Submitting SMS form...");
$res = $ua->request(POST "$baseURL/userpages/web2txt.fcgi"),...);
$res->is_success or giveUp($res->status_line);
logmsg("Completed submission.");
sub giveUp
{
my $msg = shift;
print scalar localtime(time) . "Error: $msg\n";
exit(1);
}
...
but your newer version has nice features that many
folks may appreciate more than this simple-minded approach
There may be better idioms than what I have suggested (which
was equivalent to your original version),
and your revised code seems to be one such idiom.
For example, you could now look at generalizing the process
by reading the stateConfig data from a file -- it'll be fun
figuring out how to get that to work with other args from
the command line to fill in slots within the stateConfig
data... Thanks for a very instructive update!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|