Hi,
I am trying to create an array of references but am getting stuck at
how/when to push the reference into the array
Below is some sample data and a snip of what I have been trying. What
is happening is that the reference $times is getting pushed into the
array before all the keys are defined so I am getting
$VAR11 = {
'back' => '16:08'
};
$VAR12 = {
'home' => '16:09'
};
$VAR13 = {
'morning' => '09:24',
'dom' => '09',
'day' => 'Fri'
};
$VAR14 = {
'out' => '13:10'
};
$VAR15 = {
'back' => '14:17'
};
what I'd like is
$VAR11 = {
'dom' => '09',
'day' => 'Fri' '
'morning' => '09:24',
'out' => '13:10',
'back' => '14:17',
'home' => '16:09'
};
Can someone point out where I am going wrong please.
Thanx.
Dp.
======== My effort ===============
use strict;
use warnings;
...snip
my @times;
my ($i,$key,$day,$dom,$mon,$time,$hour,$week_starting);
my $times;
while (defined($i = <FH>)) {
next if ($i !~ /^(x|j|k|z)/);
chomp($i);
# day dom
mon time hour
($key,$day,$dom,$mon,$time,$hour) = ($i =~
/^(\w)\s+(\w+)\s+(\d+)-(\w+)-\d+\s+(\d+:\d+):.*(\d+:\d+|-\d+:-\d+)/);
my $colour = 'black';
if ($key =~ /x/i ) {
$times = {
day => $day,
dom => $dom,
morning => $time,
};
}
elsif ($key =~ /j/ ) {
$times = { out => $time};
}
elsif ($key =~ /k/) {
$times = { back => $time};
}
elsif ($key =~ /z/) {
$times = { home => $time};
}
push(@times,$times);
}
===== Data Sample ===============
x Tue 06-Jun-2006 08:18:22 2006 2:11 [OKAY] $
j Tue 06-Jun-2006 12:51:33 2006 4:33 [OKAY] $
k Tue 06-Jun-2006 13:21:27 2006 0:30 OK+SHL $
z Tue 06-Jun-2006 16:18:52 2006 2:57 [OKAY] 7:20 $
~
%%
x Wed 07-Jun-2006 08:39:05 2006 0:44 [OKAY] $
j Wed 07-Jun-2006 13:11:23 2006 4:32 [OKAY] $
k Wed 07-Jun-2006 13:41:04 2006 0:30 OK+SHL $
z Wed 07-Jun-2006 17:51:18 2006 4:10 [OKAY] 8:42 $
~
%%
x Fri 09-Jun-2006 09:24:05 2006 1:05 [OKAY] $
j Fri 09-Jun-2006 13:10:56 2006 3:46 [OKAY] $
k Fri 09-Jun-2006 14:17:40 2006 1:06 OK+SHL $
...snip
=======================
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>