APM: Null fields and 100% porcessor

Mike Stok mike at stok.co.uk
Wed Apr 2 09:33:49 CST 2003


On Wed, 2 Apr 2003, Mike South wrote:

> If you do something like this:
> 
> 	while(my @newdata = $newsth->fetchrow_array()){
> 
> 		# every undef in @newdata will get set to "N/A" here
> 		for (@newdata) { $_ = 'N/A' unless defined $_ };
> 
> 		print "after: $newdata[1] - $newdata[2]\n";
> 
> 		...
> 	}
> 
> you won't be interpolating $newdata[1] into the string until after
> you have done the check/correction for undefs.

This may not be applicable to your particular code, but you can take 
advantage of .= not generating warnings when you catenate onto an undef 
value, so you can avoid an explicit test for definedness if you're just 
planning to print some strings e.g.

#!/usr/bin/env perl

use warnings;

@list = ('foo', 'bar', undef, '', 'baz');

print "List is @list\n";

$_ .= '' foreach @list;

print "List is @list\n";

__END__

The first print will grumble but the second is OK.

This is foe interest's sake only.

Mike

-- 
mike at stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       | GPG PGP Key      1024D/059913DA 
mike at exegenix.com                  | Fingerprint      0570 71CD 6790 7C28 3D60
http://www.exegenix.com/           |                  75D2 9EC4 C1C0 0599 13DA




More information about the Austin mailing list