in reply to hash initialisation

Yes, you are :)

There are a couple of optimisations you can make here. Firstly, you have may constructs like:

for ('something' .. 'something else') { my $var = $_;

where you can use:

for my $var ('something' .. 'something else') {

Secondly, and more importantly, at each level you initialise the elements to empty lists, with code like:

$bucket{$x}{$y} = ();

But on the next level down ,you overwrite it with an reference to a hash. The initial assignment is unnecessary.

In fact, you can simply the whole thing to:

for my $month ('02'..'03') { for my $day ('00' .. $mons{$month}) { for my $hour ('00' .. '24') { for my $minute ('00' .. '59') { $bucket{$month}{$day}{$hour}{$minute} = [0,0]; } } } }
--
<http://www.dave.org.uk>

"Perl makes the fun jobs fun
and the boring jobs bearable" - me

Replies are listed 'Best First'.
Re (tilly) 2: hash initialisation
by tilly (Archbishop) on Mar 27, 2001 at 06:34 UTC
    If performance matters then temporaries may be your friend. For instance the following should run several times faster than your code:
    foreach my $month ('02'..'03') { my $m_bucket = $bucket{$month} = {}; foreach my $day ('00' .. $mons{$month}) { my $d_bucket = $m_bucket->{$day} = {}; foreach my $hour ('00'..'23') { my $h_bucket = $d_bucket->{$hour} = {}; foreach my $minute ('00'..'59') { $h_bucket->{$minute} = [0,0]; } } } }
    (A useful trick I have put to good use in the past.)
Re: Re: hash initialisation
by agoth (Chaplain) on Mar 26, 2001 at 19:30 UTC
    doh!! :),
    Plus I just realised that hours in the day don't go from 00 to 24,
    well not unless you've had a few too many beers