Mark Knoop <> wrote:
> Steve Dawson wrote:
>
>> If you're retrieving data from an SQL database, you could see if it
>> supports ISNULL(). It allows you to select an alternate value that
>> will be returned if the requested field is null. Maybe you can use
>> that to avoid your undef...
>
> This was one way to approach it but it still means I have to go
> through and tend to each field in each query individually which I
> feel is not really bomb-proof as I won't know if I've missed one
> until it happens. I wondered whether something like this could be set
> globally?
>
> Thinking about this though I would really prefer to do it in perl and
> basically get it to suppress warnings regarding the use uninitialized
> strings and just use '' so that if I get unexpected parameters at
> runtime, not just from a query, I won't end up causing a warning. Or
> am I missing the point of warnings?
In that case you may need to change your design a little. There is an
old adage in programming which says that most problems can be solved by
adding an extra level of indirection. In this case instead of calling
the fetch function directly, you call a subrouting that performs the
fetch and translates undef to your preferred value before returning the
results. For example (untested):
sub my_fetchrow_array {
my $sth = shift;
my @row = $sth->fetchrow_array;
foreach (@row) {
$_ = "" unless defined $_;
}
return @row;
}
HTH
--
Brian Raven
=================================
Atos Euronext Market Solutions Disclaimer
=================================
The information contained in this e-mail is confidential and solely for the
intended addressee(s). Unauthorised reproduction, disclosure, modification,
and/or distribution of this email may be unlawful.
If you have received this email in error, please notify the sender immediately
and delete it from your system. The views expressed in this message do not
necessarily reflect those of Atos Euronext Market Solutions.
L'information contenue dans cet e-mail est confidentielle et uniquement
destinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee.
Toute copie, publication ou diffusion de cet email est interdite. Si cet e-mail
vous parvient par erreur, nous vous prions de bien vouloir prevenir
l'expediteur immediatement et d'effacer le e-mail et annexes jointes de votre
systeme. Le contenu de ce message electronique ne represente pas necessairement
la position ou le point de vue d'Atos Euronext Market Solutions.
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs