#!/usr/local/bin/perl use strict; use warnings; use Spreadsheet::WriteExcel; our %information; open FILE, ">>",'D:\My Code\Records.xls' or die "$!"; binmode FILE; my $workbook=Spreadsheet::WriteExcel->new(\*FILE); my @info = ('Name','Age','Specialization'); #adding a worksheet and writing headings my $worksheet=$workbook->add_worksheet('Personal'); $worksheet -> set_column('A:C',20); for (my $i=0; $i<=$#info;$i++){ foreach my $key(@info){ $worksheet->write(0,$i,$info[$i]); } } #adding records and initializing a row counter since each value in the hash will have a row print "How many Records do you want to enter?\n"; my $records =<>; chomp $records; my $counter=1; while($counter<=$records){ my $col_counter=0; foreach my $key (@info){ print "Enter $key\n"; $information{$key}=<>; chomp $information{$key}; $worksheet->write($counter, $col_counter, $information{$info[$col_counter]}); #indexing @info will give $key $col_counter++ if ($col_counter<=$#info); } $counter++; }