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!


In reply to Re: Perl2SMS (for Vodafone Australia) by graff
in thread Perl2SMS (for Vodafone Australia) by hagus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.