Brian Raven wrote:
> 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
>
HTH? That's an understatement!! Genius - thankyou.
Mark
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs