Hi,
I've been trying to insert an array ref within a hash. I wrote a test program which was successful, but my real program requires the redefinition of the arrays to be done within an if block. When done in the if block it overwrites previous values. Whe done outside the if block a new array is created.
I'm assuming that because I'm redeclaring within the if block this new array doesn't only has scope within the if block therefore the outer one hasn't been redefined.
Here's the code that works:
my(%details,%all_details,$index,@stFrame,@eFrame);
$stFrame[0] = 6; $stFrame[1] = 14; $stFrame[2] = 18; $stFrame[3] = 31; $stFrame[4] = 36;
$eFrame[0] = 13; $eFrame[1] = 17; $eFrame[2] = 30; $eFrame[3] = 35; $eFrame[4] = 43;
$details{'start'} = [EMAIL PROTECTED]; $details{'finish'} = [EMAIL PROTECTED]; $details{'data'} = "Data 1";
$all_details{96} = \%details;
############################ my(%details,@stFrame,@eFrame);
$stFrame[0] = 10; $stFrame[1] = 11; $stFrame[2] = 39; $stFrame[3] = 89; $stFrame[4] = 130;
$eFrame[0] = 10; $eFrame[1] = 38; $eFrame[2] = 88; $eFrame[3] = 129; $eFrame[4] = 149;
$details{'start'} = [EMAIL PROTECTED]; $details{'finish'} = [EMAIL PROTECTED]; $details{'data'} = "Data 2";
$all_details{97} = \%details;
*************************************************************** And here's the code with issues:
my(@data,$line,$arrIndex,@tempDB,$dbSize); my($firstLine,$currRoll,$lineCount) = (1,0,0); my(%rolls,%range,@stFrame,@eFrame); @data = ("96\t6\t13","96\t14\t17","96\t18\t30","96\t31\t35","96\t3 \t43","97\t10\t10","97\t11\t38","97\t39\t88"); $dbSize = @data; foreach $line (@data) { $lineCount++;
chomp($line); $line =~ s/\r//g; @tempDB = split(/\t/, $line);
if($firstLine) # Assign inital values { $firstLine = 0; $arrIndex = -1; $currRoll = $tempDB[0]; }
$arrIndex++; if($tempDB[0] != $currRoll) # Last line of @db { print "$tempDB[0]\t$currRoll\n"; print "Inserting\n";
$range{'start'} = [EMAIL PROTECTED]; $range{'end'} = [EMAIL PROTECTED]; $rolls{$currRoll} = \%range;
$arrIndex = 0;
$currRoll = $tempDB[0];
### This isn't redefining outer array nor hash my(%range); my(@stFrame); my(@eFrame); }
$stFrame[$arrIndex] = $tempDB[1]; $eFrame[$arrIndex] = $tempDB[2];
if($lineCount == $dbSize)
{
### This needs to be redefined so as not to overwrite
previous value
$range{'start'} = [EMAIL PROTECTED]; $range{'end'} = [EMAIL PROTECTED];
$rolls{$currRoll} = \%range;
}
}
-- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.300 / Virus Database: 265.8.3 - Release Date: 31/01/2005
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>