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?
use strict;
$cust_data = {};
while ($condition) {
...
$cust_data = get_cust_data();
if ($condition2) {
if (send_mail($cust_data)) {
print $cust_data->{'customer'};
...
}
else {
if (send_mail($cust_data)) {
print $cust_data->{'customer'};
...
}
}
--
Randy Perry
sysTame
Mac Consulting/Sales