What you've got there is an array reference with a hash reference as its only element. To make an anonymous hash reference, you just use curlies ({}). Since you want to read in multiple comma-delimited rows, you probably want an array of hash references, one hashref for each row.
my @records; # store the hashrefs in here my @keys = qw(Emp_No Emp_Lname Emp_Fname Emp_SSN Emp_DOB Emp_aka); open(IN,"input.txt") or die("Can't open input.txt"); while(<IN>) { chomp; my %Employee_Rec; @Employee_Rec{@keys} = split /,/, $_; # hash slice print "$Employee_Rec{Emp_No} \n"; print "$Employee_Rec{Emp_Lname} \n"; print "$Employee_Rec{Emp_Fname} \n"; print "$Employee_Rec{Emp_SSN} \n"; print "$Employee_Rec{Emp_DOB} \n"; print "$Employee_Rec{Emp_aka} \n"; push @records, \%Employee_Rec; } close(IN);
To inspect @records and make sure you've built it correctly, you can use Data::Dumper.
In reply to Re: Loading an anonymous hash
by friedo
in thread Loading an anonymous hash
by pglenski
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |