Tiling windows with perl script - are nested arrays a bad idea?

Question!

I am writing a script which would tile X11 windows dynamically in Perl. So far I am going to use an array of arrays containing windows coordinates, sizes and ids to store state of tiled windows during session. Is it a good idea or should I organize this information in any other way?



Answers

Arrays of arrays, or arrays or hashes, or hashes of hashes, or hashes of arrays of hashes of hashes of arrays are wonderful in perl and one of the reasons that data processing in perl is so easy. You do not need to fear them!



Well, the standard representation of compound structures in Perl is a (blessed) hash. Unless you have serious performance concerns, grouping data into hashes would be a good idea.

OTOH, arrays are good for uniform data. But when you have data with unique ids (X window windows DO have ids, right?) a hash is a more natural structure, again. So you just say

do_something($windows-


The guideline I follow is: If maintaining the order of the elements is important, use an array; otherwise, use a hash.

Hashes are slower than arrays but by choosing meaningful keys they can be easier to maintain. So I prefer them over arrays.



This video can help you solving your question :)
By: admin