Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Perl2SMS (for Vodafone Australia)

by graff (Chancellor)
on May 26, 2002 at 04:26 UTC ( [id://169334]=note: print w/replies, xml ) Need Help??


in reply to Perl2SMS (for Vodafone Australia)

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!

Replies are listed 'Best First'.
Re: Re: Perl2SMS (for Vodafone Australia)
by hagus (Monk) on May 26, 2002 at 13:16 UTC
    ++, many thanks for the feedback!

    I think, personally, when you look at the core data of the new one (the statConfig array), it's simpler than my first effort. Everything you need to know is in that array, and it just boils down to a few lines ... when you move the package into a separate file, the main routine is just the data structure, newing up the class, and calling a single method!

    The complexity of introducing a data structure and whatnot is I guess offset by the benefits of generacity (is that a word?). And separation of functional code from data. And all that good stuff.

    Moving forward, I think I might tack a Tk interface on the front, and perhaps add HTML::Parse in there to take care of errors. Keeping it generic, of course :)

    Re: reading the data in from a file - if it got really complex I would make it XML. Since it's only a handful of GETs and POSTs, the effort of a nice config file is hard to justify.

    Also: it's using https rather than http for everything. Wouldn't want people sniffing those SMS!

    --
    Ash OS durbatulk, ash OS gimbatul,
    Ash OS thrakatulk, agh burzum-ishi krimpatul!
    Uzg-Microsoft-ishi amal fauthut burguuli.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2024-04-23 10:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found