|Think about Loose Coupling|
A strange old perl bug: "Can't use an undefined value as an ARRAY reference" error given for a misleading/wrong line numberby elumelum (Initiate)
|on Feb 13, 2013 at 01:05 UTC||Need Help??|
Here's a little program:
Running this code under perl v5.8.8 gives me:
Can't use an undefined value as an ARRAY reference at arrayref2.pl line 8.
...which is the check on the defined array reference.
Running this code under perl v5.10.1 (*) (with 59 registered patches), the next newest perl I had available, produces this output:
Can't use an undefined value as an ARRAY reference at arrayref2.pl line 11.
...which is the check on the undefined array reference.
When laid out this way, I think most would agree that it is easily identifyable as an issue in perl v5.8.8.
However, when I ran across this while working on some legacy perl code at my job (hence the old version(s)) and this situation was masked by much more complex conditionals that were much more deeply nested, this was a real pain to figure out! I was especially thrown off at first when I changed the equivalent of the first if to:
...and it still gave the same undefined array reference error for that line! Though that is also part of what led me to discovering the issue ultimately.
I was unable to turn up anything quite like it searching the web, as for obvious reasons, most of the results were dealing with situations in which the line number reported actually contained an undefined variable being used as an array reference.
I thought I would write this up here on the off-chance that it might turn up amongst search results for someone else if they run into this same issue.