in reply to
What is the better way to store and display data.
It really depends on the use. If I'm saving a list of items for my own use only, and the list isn't terribly long, and I'm not going to do complex queries on it, I'm likely to just save it in a text file, as you've shown it here. A text file gives me several advantages:
- It's quick to create. No need to set up a database or design tables with keys and so on; just type in the data with a consistent pattern. If it's already in this format, even better.
- It's fast and easy to edit. I can edit it with a simple text editor via SSH from anywhere. If I want to make a change to John Doe's entry, I can do that far faster with a text editor than I ever could through the most convenient GUI -- and I don't have to design the interface.
- It's trivial to move it to or duplicate it on another system, simply by copying the file. Yes, databases can be copied, but generally they should be dumped/loaded, which is at least twice as many steps.
- It's reasonably easy to parse it and pull out the data I want. In your sample, set the input record separator to a blank line and grep records for whatever. Simple.
On the other hand, if other people need to be able to work with the data, or if there are millions of records, or if I need to do complex queries like "WHERE city = 'this' AND Status LIKE '%that%', it's probably worth the time to put it into a real database.
The one thing I wouldn't be likely to do with data like this would be to put it in a hash. First of all, a hash requires unique keys. Can you be sure there will never be two John Does in your list? So you're probably looking at an array, not a hash. And you're going to need code to load the data into the array from its current format, and then print it back out of the array into this format. So why not use that code to save it in this clear text format, rather than saving the array in some serialized format? Saved as plain text, it's much easier to edit, as I mentioned above.
Available for small or large Perl jobs; see my home node.