Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Comment on

( #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

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (4)
    As of 2018-01-19 12:28 GMT
    Find Nodes?
      Voting Booth?
      How did you see in the new year?

      Results (218 votes). Check out past polls.