> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On 
> Behalf Of Mark Knoop
> Sent: Tuesday, November 01, 2005 12:05
> To: [email protected]
> Subject: Warnings, fetchrow and uninitialized values.
> 
> Hi there
> 
> After taking on board the advice of some the guys here I have 
> started using
> 'use warnings' as a matter of course.
> 
> I am retrieving fields from a db using the following principle
> 
> ...
> my %values;
> while (my ($id, $value) = $sth->fetchrow) {
>       $values{$id} = $value;
> }
> 
> ...
> 
> to get all the fields first and then
> 
> ...
> 
> foreach my $id (sort keys %values) {
> 
>       my $value = $values{$id};
> 
>       print <<EOF;
> 
>       some stuff
>       $value
>       some more stuff
> 
> EOF
> 
> }
> 
> In practice there are lots of values and extra bumf in the 
> string concat
> hence moving the value from hash to scalar for clarity plus 
> it seems to
> process a lot quicker than mixing up the query and the printing.
> 
> Problem is that if the value in the database is NULL then I 
> get a warning
> saying 'Use of uninitialized value in concatenation (.) or 
> string at line
> <wherever the print EOF is>'
> 
> Any thoughts on the neatest way of handling this?
> 
> Cheers
> Mark

Something like this:

my $value = $values{$id};
$value = 'NULL' unless (defined($value));

Dirk Bremer - Senior Systems Engineer - ESS/AMS - NISC Lake St. Louis MO
- USA Central Time Zone
636-755-2652 fax 636-755-2503

[EMAIL PROTECTED]
www.nisc.coop 

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to