Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I've voluteered to write a small script for a web community.

The details are pretty meaningless, but it's a small SQL database containing Quotes of the Day kind of thing.

All that's needed is to connect to an SQL DB, and edit, save, add and delete quotes via a web front end.

It would normally take me a couple of hours to fix the whole thing up, but the person I'm writing it for likes the code to be object-oriented.

I don't need details of exactly the code I'd use, but I have to admit I still don't really get the OO philosophy.

Here's what I'd probably do for a script like that:

  • create a script
  • feed it a "mode" via the form/query string every time like "if($mode eq 'edit'){ open the db, get record x, populate the fields }" or "if($mode eq 'save'){ open the db, put the field contents into record x}" and so on, the default mode being "none of the above" or start-up mode.
  • create the right forms and HTML code for each "mode".

What's the OO way to approach a simple task like that? I need to make everything into a function, essentially, and then call the functions as methods of the objects? So what are my objects?

As you can see, I've got a mental block about this -- I really see the whole thing as procedures, so I'm hoping my fellow monks can help me translate that into Objects with Methods.
--

($_='jjjuuusssttt annootthheer pppeeerrrlll haaaccckkeer')=~y/a-z//s;print;

In reply to Object-Orienting A Procedural Script by Cody Pendant

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



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-19 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found