SPUG: MORE INFO: Array Naming Question

Chris Wilkes cwilkes-spug at ladro.com
Wed Feb 4 11:35:44 CST 2004


On Wed, Feb 04, 2004 at 10:19:36AM -0700, North, Walter wrote:
> 
> More storage arrays are on the way and I'd like to combine the data
> however I haven't been able to come up with how to create a hash
> with the storage array name as a hash that contains another hash
> of the data keyed by date.

You might want to look into making a perl module so that you can do
something like this:

open (FOO, "datafile.txt");
while (<FOO>) {
	chomp;
	my @items = split;
	push @storage_units,
     My::StorageUnit->new($items[0], @items[1..$#items]);
}
close FOO;

so now in the array you have all your storage units and you can then do
things like

  $unit = $storage_units[0];
  print "Storage unit " . $unit->getName() . " was purchased on " .
    $unit->getDatePurchased() . "\n";

so you don't have to remember "Did I make that a hash, hash of hashes,
array of hashes?"  What's better is that when someone else takes over
this code their head won't start spinning and just has to know "To get
the date I just do a ->getDatePurchased()"

Chris



More information about the spug-list mailing list