The above methodology will create an array of hashes. I assumed that ACCTS was probably referring to account information so a list of accounts is probably what you are looking for... though I could be wrong. So each account record is now an anonymous hash within your ACCTS array.#!/usr/bin/perl -w use strict; use Dumpvalue; my @ACCTS; open(IN, "< myfile") || die "Help!\n"; while (<IN>) { my ($id, $name, $street, $city, $zip, $phone, $start_dt) = split(/\|\| +/, +$_); ###push onto the array ACCTS an anonymous hash reference from the valu +es you just split. push(@ACCTS, {'name' => name, 'street' =>$street, 'city' =>$city, 'zip +' =>$zip, 'phone' =>$phone, 'start_dt' =>$start_dt, 'id' =>$id}); } close IN; ###always check what you have created. dump_ref(\@ACCTS); sub dump_ref { my $ref = shift; my $dumper = new Dumpvalue; $dumper->dumpValues($ref); }
Would be how you get back at your data.foreach(@ACCTS){ #dereference the elements of the hash contained in this #row of your array with the arrow... its just easier to #read in my opinion. print "This accounts id is ".$_->{id}."\n"; }
In reply to Re: How to use hashes well
by injunjoel
in thread How to use hashes well
by cosmicsoup
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |