Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Kia ora, Lady_Aleena, sure

  1. No it isn't, just happens to be the version I use (faster than writing use strict; use features;. Also gives hints about the version of Perl I am using, in case people do run into issues with any scripts I have created)
  2. In the sample I provided, this is main:
    my %movies_data = ( 'Firefly' => { 'title' => 'Firefly', 'startyear' => '2002', 'endyear' => '2003', 'media' => 'tv', }, 'Criminal Minds' => { 'title' => 'Criminal Minds', 'startyear' => '2005', 'endyear' => 'tbd', 'media' => 'tv', }, 'The 10th Kingdom' => { 'title' => 'The 10th Kingdom', 'startyear' => '2000', 'endyear' => '', 'media' => 'miniseries', }, 'Iron Man' => { 'title' => 'Iron Man', 'startyear' => '2008', 'endyear' => '', 'media' => 'film', 'basedon' => 'comics', 'company' => 'Marvel Comics', }, 'Tin Man' => { 'startyear' => '2007', 'title' => 'Tin Man', 'media' => 'miniseries', 'basedon' => 'novel', 'company' => 'L. Frank Baum' }, 'The Avengers (1998)' => { 'title' => 'The Avengers (1998)', 'startyear' => '1998', 'media' => 'film', 'basedon' => 'television series', 'company' => 'Thames Television', }, ); my $library = library->new(name => "Lucky's"); foreach my $movie (values %movies_data) { $library->add_movie(movie->new(%$movie)); } $library->print();
    From this, you can see that $movie is a reference to each of the hashes contaning the movie info (startyear, endyear, etc). When I call movie->new(%$movie) it is a call to the new function in the package movie, passing in the de-referenced hash containing the movie information. new is expecting a hash of stuff and deals with it appropriately when it creates the movie object. As for copying it, you don't have to do this - You can store this information in a myriad of ways (I would suggest a read-only XML file that you can easily backup, which your scripts can load easily)
  3. It won't get a value if I don't give it one. I didn't implement run_time as I was just trying to show a quick sample of how to create an OO object. Implementing this should be pretty straight-forward (and I would expect no end_year would be handled appropriately by run_time

Heh, certainly looks pretty meaty. In a more OO fashion, I would expect lookup to be a single function within a library class, that returns an object from the library (movie, tv show, whatever). Then getting any of the underlying state information of the object that the caller wants is placed back onto the caller, who simply asks the object for that piece of information.

UPDATE: You can copy the original sample I provided as-is, stick it all into a single script, change the use 5.16.2; line to use 5.8.8;, save it and run it - It should work just fine (though might complain about say (not sure when this feature was implemented), which you can just change to print.


In reply to Re^3: How do I go from procedural to object oriented programming? by SimonPratt
in thread How do I go from procedural to object oriented programming? by Lady_Aleena

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 romping around the Monastery: (4)
As of 2024-03-28 16:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found