Tag Archives: lists

Why lists are amazing

When I was working on my linguistics project, I ran into a wall. Perl doesn’t allow for dynamic creation of arrays. I had used this feature/bug of the BASH shell during an internship at a theoretical chemistry lab, as it allowed me to create an array, whose elements were dynamically created arrays, named according to whatever variable I felt like.

For example, in the case of a cyclohexane, I could have a condition (if $atom = ‘C’) and then create my array as follows:


In Perl of course, the solution was to feed my input text to a function, and create a hash table with the structure word{wordcount} for my key-value pair. However, as it turns out, there is an even more elegant solution: lists.

  • Lists can be accessed as arrays (check)
  • Elements can be added to lists as arrays (check)
  • Elements can be arrays (check)

Of course, for the use I was intending, lists are absolutely useless. I cannot really go through an array writing $words[$cow[$xvar]], (well, it’s feasible, but slightly useless). On the other hand, for generating a dictionary spell-checker (which is a word-LIST) lists would consume far less memory due to the absence of the value partner (useful in the case of memory intensive lists on older systems).

Lists are fairly awesome in their capacity. I have not yet tested if they can be used to replace the STRUCT vartype from C, but if they can, then that is awesome.