I only offered that because if you're dealing with a largish amount of data, it's significantly more efficient to deal with a sequential data structure (such as an array) than a "random-access" one with a sequential key. | [reply] |
do something with $array[8]
Now, do something with $array[9]
Well, that means nothing to me. How do I know that the 8th element is
the 'FNAME' field and the 9th is the 'LNAME' field? I don't! Also, what happens
when you change the table? BAM! Things can get seriously out of whack if I make a
'MNAME' field after the 'FNAME' field.
So, I started off by changing all his fetchrow_array's to fetchrow_hashref's. Now,
I had a more intuitive (and scalable) way to do things like:
do something with $hashref->{FNAME}
do something else with $hashref->{LNAME}
Don't forget $hashref->{MNAME}
Did I sacrifice some speed by using a hash(ref)? Maybe. Is the script now easier to read and
maintain? Definitely! So, which is more efficient? I say it is more efficient to have readable and
maintainable code. This saves work-time, which is much more measurable than fractions of a second differences
that may be gained/lost with using one data structure vs. another.
So, I disagree that it is more efficient to use an array, based on my experiences. But, regardless, this was an
exercise to find AWTDI ;-)
Cheers,
KM | [reply] [d/l] [select] |
print @array; # gives the same result as:
print qq{$hash{$_}} for sort keys %hash; # this
My conclusion (for now ;-): arrays are easier when your keys are always going to be sequential integers.
| [reply] [d/l] [select] |