On Tuesday, Jun 17, 2003, at 09:33 US/Pacific, Daedalus wrote: [..]

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

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


I would have done that as

my ($dbh, $sth, $searchid, $name, $address1, $address2, $address3, $address4) =
('', '', '', '', '', '', '', '');


but looking at your code, you may want to
do the shorter list of only

my ($dbh, $sth, $searchid); # these are initted and guarded elsewhere

        my ($name, $address1, $address2, $address3 ,$address4) =
                ('', '', '', '', '')

this way you don't have to interpolate the "" token, nor have to walk the array...
Also iv you need to change the variable list you can keep it local to
this function and not HOPE for the side effects of using a global....


[..]
$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: you may want to think about using


CGI::Carp

for those 'die' - in case it was not already defined.


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

[..]

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.)

Correct Idea - while I have not peeked at the innards of


DBD::Oracle

you can do that with

perldoc -m DBD::Oracle

or we can look at the following demonstration code:

#------------------------
#
sub do_funk
{

        my ($name, $address1, $address2, $address3 ,$address4) =
                ('', '', '', '', '');

        some_funk(undef,\($name, $address1, $address2, $address3 ,$address4));
        #
        # my habit is to set the assignment up this way
        # so it 'reads' a little simpler - a la
        #       make the assignment unless condition...
        #
        $address4 = 'UNDEFEED' unless defined($address4);

        print "$name, $address1, $address2, $address3 ,$address4 \n";
        
} # end of do_funk

#------------------------
#
sub some_funk
{
        my ($first, @arrayRef) = @_;
        
        print "Ok, \$first is undef\n" unless $first;
        
        ${$arrayRef[0]} = 'bob';
        ${$arrayRef[1]} = 'b1';
        ${$arrayRef[2]} = 'b2';
        ${$arrayRef[3]} = 'b3';
        ${$arrayRef[4]} = undef;

} # end of some_funk

do_funk();

You can play around with that and see how that

\($name, $address1, $address2, $address3 ,$address4)

is a way of passing the variables by reference...

An Alternative Strategy would look like say:

#------------------------
#
sub do_funk
{

        my ($name, $address1, $address2, $address3 ,$address4);
        
        my @thingies = \($name, $address1, $address2, $address3 ,$address4);

some_funk(undef, @thingies);

        foreach my $ref (@thingies)
        {
                $$ref = '' unless(defined($$ref));
        }
        print "$name, $address1, $address2, $address3 ,$address4 \n";
        
} # end of do_funk

this way if ANY of the variables get undeffed, you can initialize them...


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

nope both questions are Most Excellent and are starting to dig into some of the problems.


ciao drieux

---


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



Reply via email to