J
Jan
Hi,
I'm struggling with references again. Underneath you will find a code
snippet with some comments interleaved to tell what's going on.
# start code snippet.
$recordIndex = 0;
open (GROUPS, "<groupsfile.txt") or die "Cannot open $groupsFile\n";
while ($line = <GROUPS>)
{
@juniorMembers = ();
@seniorMembers = ();
#
# Snipped away code in which the two preceding arrays are populated
and in which
# which $group gets a valid value. This code was tested and correct.
So for
# keeping things easy I'll leave this 'huge' part out...
#
foreach $juniorMember(@juniorMembers)
{ push( @{$juniorArray}, $juniorMember) ; }
foreach $seniorMember(@seniorMembers)
{ push( @{$seniorArray}, $seniorMember) ; }
# Since I'm in while loop I try to store my data into an anonymous
# array by using a hard reference (e.g. $juniorArray)
$myrecord = { GROUP => $group,
JUNIOR => $juniorArray,
SENIOR => $seniorArray };
$database[$recordIndex++] = $myrecord;
}
# End code snippet.
Next thing I know, for each record I have in my 'database' array, when
dereferencing the arrays, about the same array contents. I do know
that I do overwrite my references to the arrays, but hoped that would
have been solved by storing these references in the anonymous hash.
dumb, dumber...
So perl doesn't know the location of my 'junior' and 'senior' arrays
data anymore, I guess. Can someone offer some advice on more proper
ways to come out of this while loop with the array data still intact ?
Hoping I stated the problem correctly,
Jan
I'm struggling with references again. Underneath you will find a code
snippet with some comments interleaved to tell what's going on.
# start code snippet.
$recordIndex = 0;
open (GROUPS, "<groupsfile.txt") or die "Cannot open $groupsFile\n";
while ($line = <GROUPS>)
{
@juniorMembers = ();
@seniorMembers = ();
#
# Snipped away code in which the two preceding arrays are populated
and in which
# which $group gets a valid value. This code was tested and correct.
So for
# keeping things easy I'll leave this 'huge' part out...
#
foreach $juniorMember(@juniorMembers)
{ push( @{$juniorArray}, $juniorMember) ; }
foreach $seniorMember(@seniorMembers)
{ push( @{$seniorArray}, $seniorMember) ; }
# Since I'm in while loop I try to store my data into an anonymous
# array by using a hard reference (e.g. $juniorArray)
$myrecord = { GROUP => $group,
JUNIOR => $juniorArray,
SENIOR => $seniorArray };
$database[$recordIndex++] = $myrecord;
}
# End code snippet.
Next thing I know, for each record I have in my 'database' array, when
dereferencing the arrays, about the same array contents. I do know
that I do overwrite my references to the arrays, but hoped that would
have been solved by storing these references in the anonymous hash.
dumb, dumber...
So perl doesn't know the location of my 'junior' and 'senior' arrays
data anymore, I guess. Can someone offer some advice on more proper
ways to come out of this while loop with the array data still intact ?
Hoping I stated the problem correctly,
Jan