#!/usr/local/bin/perl use warnings; use strict; my @Month_Data; # $Month_Data[0] is January's data $month_data[11] is December's $Month_Data[0]=0; $Month_Data[1]=5; print "\nFrom an array\n"; print "January : ", defined $Month_Data[0] ? $Month_Data[0] : 0, " widgets\n"; print "February: ", defined $Month_Data[1] ? $Month_Data[1] : 0, " widgets\n"; print "December: ", defined $Month_Data[11] ? $Month_Data[11] : 0, " widgets\n"; # with names print "\nFrom synchronised arrays with names\n"; my @Month_Names=qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); for my $i (0..$#Month_Names) { print "$Month_Names[$i]: " , defined $Month_Data[$i] ? $Month_Data[$i] : 0, " widgets\n"; } # A structure (Array of Arrays) my @Structure; foreach my $Month (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)) { push @Structure, [$Month, 0] } print "\nFrom an array of arrays, we zero initialised these so no need to check defined\n"; foreach my $Month_Data (@Structure) { print "$Month_Data->[0]: $Month_Data->[1] widgets\n"; } # Finaly a hash, order is lost but lookup by month is easy my %Month_Records; foreach my $Month (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)) { $Month_Records{$Month}=0 } print "\nFrom a hash, order is lost\n"; foreach my $Month (keys %Month_Records) { print "$Month: $Month_Records{$Month} widgets\n"; } print "\nBut lookup by any random month is easy\n"; print "July: $Month_Records{Jul} widgets\n"; __END__ From an array January : 0 widgets February: 5 widgets December: 0 widgets From synchronised arrays with names Jan: 0 widgets Feb: 5 widgets Mar: 0 widgets Apr: 0 widgets May: 0 widgets Jun: 0 widgets Jul: 0 widgets Aug: 0 widgets Sep: 0 widgets Oct: 0 widgets Nov: 0 widgets Dec: 0 widgets From an array of arrays, we know all these are zero initialised Jan: 0 widgets Feb: 0 widgets Mar: 0 widgets Apr: 0 widgets May: 0 widgets Jun: 0 widgets Jul: 0 widgets Aug: 0 widgets Sep: 0 widgets Oct: 0 widgets Nov: 0 widgets Dec: 0 widgets From a hash, order is lost Mar: 0 widgets Nov: 0 widgets Apr: 0 widgets Oct: 0 widgets May: 0 widgets Sep: 0 widgets Jan: 0 widgets Jul: 0 widgets Dec: 0 widgets Feb: 0 widgets Jun: 0 widgets Aug: 0 widgets But lookup by any random month is easy July: 0 widgets