|laziness, impatience, and hubris|
.csv file in to hash of hashes for a Berkley DB (for a hash newbie)by Doozer (Scribe)
|on Jun 12, 2013 at 08:15 UTC||Need Help??|
Doozer has asked for the
wisdom of the Perl Monks concerning the following question:
I have been working with perl for a little while and have now entered in to the world of hashes. I will outline what I want to achieve and then show examples of my data and scripts below.
I currently have a .csv file which holds information for 324 pieces of equipment (Set Top Boxes). The first column holds our unique equipment locator and the following columns hold further information such as serial number, date installed, asset numbers, etc.
Each piece of equipment has its own row which is comma delimited (example below):
Zone1 - Box1,01/06/2011,Amstrad,4F3107,0362940644,540 442 969,R007.061.38.00U,R007.061.38.00U - 03/06/2013,, - R007.061.38.00U,,172.16.121.4 D,00:19:fb:2c:56:2c,03/06/2013,0,03/06/2013
You can see from the example that the first field is our equipment locator ID which I would like to use as the main hash keys. I would then like to have the remaining details as hash values for that individual Set Top Box. This is kind of what I would want:
The aim is to be able to store all of the information for each Set Top Box but also make it searchable so I can select a Set Top Box by its unique ID (Zone1 - Box1 for example) and it will show me all of the details.My code is below.
If I execute this script it reports that all 324 boxes were added to the hash. If I set a box reference for $ARGV ($search) I keep on getting "Can't use string ("HASH(0x7ff9aa090b58)") as a HASH ref while "strict refs" in use" error. I don't think I am adding the new details for each box to the hash correctly. Any help would be very much appreciated :)