Man, you people are quick.
As others have stated:
- You created a list with one name, but then referenced it to another.
- If you used
use warnings
and use strict
, you would have gotten an error message telling you about the error.
There are lots of hints and tricks to writing legible and relatively bug free Perl code. For example, I don't use plurals in variable names. Thus, if it's a question of "fruit" or "fruits", I know it should be "fruit". I also tend to say the name of my data types by using terms like "fruitColorHash" vs. "FruitColorList" even though (Camel Casing isNotInStyleAnyMore, but then Im_an_old_grouchy_developer_who_is_set_in_his_ways).
Damian Conway's book Perl Best Practices is an excellent book that will help you learn all of those tricks and tips that will help you avoid issues like this. In fact, the book is considered such a touchstone of good Perl programming, that there's now an entire section devoted to Damian Conway's book called Perlstyle, and a program called tidyperl that will help reformat and point out places that don't follow Conway's examples.
So, go ahead and look at the Best Practices section in Perldoc (You know about the perldoc
documentation, don't you? Type in the command perldoc
and see what you get) and absorb the knowledge placed there in. Then get Conway's book.