$my_car->model("corvette");
That is against the OO-approach. Your car object is supposed to represent a real-life object (a car). You cannot change the model of a car. You can only get a new instance (a different car) for the new model.
How about this: A class CarPark which you can initialize from your file and query for Car objects.
my $park = new CarPark( filename => 'blah');
# this will read the file, and (unless the file
# is too big or can change in between) save it into
# an internal structure suitable for the lookups
# you are going to do (probably hash keyed on car model)
# so that you have to read it only once.
my $car = $park->get("pinto");
print $car->horse_power;
$car = $park->get("corvette");
# a new instance
print $car->horse_power
-
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.
|