On Thu, Jul 14, 2011 at 2:36 AM, Shlomi Fish <shlo...@shlomifish.org> wrote: > Hi Leo, > > I'm commenting on your code below because it exhibits some bad elements. > > On Wed, 13 Jul 2011 11:00:33 -0700 > Leo Susanto <leosusa...@gmail.com> wrote: > >> #!/usr/bin/perl >> use Text::CSV; >> use DBI; >> use Data::Dumper; > > There is no "use strict;" and "use warnings;" at the beginning of the file: > > http://perl-begin.org/tutorials/bad-elements/ >
Shlomi is correct here, always add use strict. > >> my %region_data; >> foreach my $region (@regions) { >> foreach my $status_string (@statuses_string) { >> $region_data{$region}{status}{$status_string}{count} = 0; >> } >> $region_data{$region}{total_count} = 0; >> } > > You can write this as: > > my %region_data = (map { $_ => { total_count => 0, > status => { map { $_ => { count => 0 } } @status_strings }, > } } @regions); > personally, I find "map" function more confusing to read compared to "foreach", "foreach" is easier on the brain since it a closer syntax to "for". but on certain cases, that involves simple 1 liner data manipulation, I prefer to use map. But apparently, many problems that I encountered can not be reduced to 1 simple line of data manipulation. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/