Hi all,

I have a cgi prog that complains about uninitialized values when I use the -w switch.
To avoid those errors I have done stuff like this:

---------------------------------------------------------------
# Up near the top with a bunch of other defs and the main prog...
my @init_array = ("","","","","","","","","","");


################################
#  function get_address        #
################################

sub get_address
{    my ($dbh, $sth, $searchid, $name, $address1, $address2, $address3, $address4) = 
@init_array;

     $searchid = $query->param('searchid');
     $searchid =~ s/[^\d]//go;

     # NOTE: If I do stuff up here with the address vars I do NOT
     # get a "uninitialized value" because of the = @init_array;

     my $sql = qq{
          SELECT
               name,
               address1,
               address2,
               address3,
               address4
          FROM
               db.addresses
          WHERE
               id = $searchid
     };# end of $sql

     $dbh = DBI->connect($connect_string, $user, $password) || die "Unable to connect: 
$DBI::errstr";
     $sth = $dbh->prepare($sql) || die "Prepare failed: $dbh->errstr";
     $sth->execute() || die "Execute failed for data retrieval: $dbh->errstr";
     $sth->bind_columns(undef, \($name, $address1, $address2, $address3 ,$address4));
     $sth->fetch || die "A record was not found for that ID");

     # NOTE: Avoid an error about uninitialized var
     # (Why do I have to do this? when I inited up top)
     unless (defined $address4){$address4 = ""};

    print "$name\n$address1\n$address2\n$address3\naddress4\n";

    return();

}# end sub get_address
----------------------------------------------------------------


This is just some quick example code to base my questions on...


1. I am using the @init_array to avoid the majority of uninitialization errors.
Is there a better way to do this?

2. Is there a better to handle the re-init of $address4? (DBD::Oracle must
return UNDEF or some such for an empty address4 field.)

3. Are both of these questions moot because I should use -w while developing
the cgi, but remove it before actual use?

Thanks all,
-Bill


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to