On Wed, May 02, 2001 at 11:27:28PM -0400, Randall Perry wrote:
> I'm baffled by perl's scoping of variables. In the code below, the
> $cust_data hash ref is inited outside the while loop. It's then set in the
> while with the results of a PgSQL query.
>
> In the if-else statement $cust_data can be seen in the 'if' but not in the
> 'else' (if I try to print a value in else, $cust_data->{'customer'}, I get
> an undeclared variable error).
>
> I understand that by using 'strict' I can't use any global variables.
>
> Can someone explain why this happens and how to make it work right?
The code that you posted doesn't provide enough details about the problem.
Your sample code starts with use strict, but you don't show how any of the
variables are declared.
If $cust_data is actually declared with my() outside the while loop, then
everything should work fine. Perhaps there is an error in your code?
Ronald
P.S. I remove the PgSQL mailing list from the list of recipients, because
the gist of your question appears to be unrelated to PgSQL.