I'm having the strangest problem. Here's the deal. I'm writing a decently ugly script that parses a spreadsheet according to options specified by the user in a config file. I have several subroutines that perform data manipulations according to the contents of the config file.
One subroutine (1) takes some data, pushes its values into a 2D array, does some manipulations to it, prepends a value to each element, and merges it back with the main array. This piece of code has been well tested, and works quite well.
Another subroutine (2) selects certain columns from the main data, pushes their values into a DIFFERENT 2D array, and merges this newly-selected array back in to the main data.
The only thing shared between these two subroutines is the main array of data (2D array). It's passed to (1), formatted, and passed back to the main loop, then passed to (2). Now here's the REALLY strange part. As I'm taking values from the main array and putting them in my temporary array, I'm checking them with print statements. The print statements don't show what I push into the temporary arry, but instead show the values that were pushed into a DIFFERENT temporary array in a DIFFERENT subroutine! Here's a code snippet to illustrate:
@data: the main block of data from the SS
@holder: the temporary array set up for manipulation purposes
$sheet, $iC, $index: Numerical indices for accessing my nested arrays.
print "Pushing ".@{@{@data[$sheet]}[$iC]}[$index]." onto holder[$sheet +][$iC]\n\n\n"; push(@{@{@holder[$sheet]}[$iC]},@{@{@data[$sheet]}[$iC]}[$index]); print "holder[$sheet][$iC] = ".@{@holder[$sheet]}[$iC]."\n";
This produces the following:
TTY9.3 is one of the values generated by subroutine (1). It was originally put into an array similar to @holder, but it was called @tempdata, and was in a completely different subroutine. Now it would seem that this shouldn't be happening, given that the two temporary arrays are of different names and scopes. The only thing that they have in common is that the nesting levels are the same (ie, @tempdata[$sheet][$iC] held TTY9.3 while @holder[$sheet][$iC] SHOULD hold a date), and as such they both get casted to full arrays through the @{} operator. Is it something strange like a mixup in whatever temporary space perl uses to cast nested arrays, or something REALLY basic that a noob like me is missing?Pushing 1-Jun-97 onto holder[0][3] holder[0][3] = TTY9.3
Can anyone help at all with this? Even a clue as to what may be happening? I can provide any additional info you need, save for the entire script (it's over 2000 lines and I'm quite new to perl so it's UGLY).
ActivePerl 5.8.0, Win2k
In reply to Strange problem with nested arrays and scoping. by Tyr_7BE
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |