If we later decide to change the implementation of our list to a hash our loop will also process the hash keys (this would most likely not be what we want). We have to change code outside our object to conform with the new internal data structure of the object.
No, you just need to change your accessor so that it returns the values instead of the whole hash. You incur the cost of building an array where you could just return a premade one before, but it's dangerous to return references to your internal data structures anyway (you lose control of what's in them). Being able to make this kind of change is most of the argument behind using accessors instead of data members in the first place.
I agree that accessors can be misused, but I'm a little worried that people are going to interpret your advice as meaning that you should always use an iterator or visitor pattern instead of returning an array. In perl, that's not necessary.
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>
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
Want more info? How to link
or How to display code and escape characters
are good places to start.