Null value in print string

  • Thread starter David G Anderson
  • Start date
D

David G Anderson

I wish to protect against a null value in the print string below:

foreach my $result (@{$response->{Details}}) {
print
join "\n",
$result->{ProductName}[0]||"no title",
$result->{Asin}[0] . "\t" .
$result->{ListPrice}[0] . "\n\n";
}

Error message when ListPrice is null:

"Use of uninitialized value in concatenation (.) or string at ... "

David Anderson
 
T

Tad McClellan

David G Anderson said:
I wish to protect against a null value in the print string below:

foreach my $result (@{$response->{Details}}) {


$result->{ListPrice}[0] = '' unless defined $result->{ListPrice}[0];

print
join "\n",
$result->{ProductName}[0]||"no title",
$result->{Asin}[0] . "\t" .
$result->{ListPrice}[0] . "\n\n";
}

Error message when ListPrice is null:

"Use of uninitialized value in concatenation (.) or string at ... "


That is a *warning* message, not an error message.
 
E

Eric J. Roode

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

(e-mail address removed) (David G Anderson) wrote in
I wish to protect against a null value in the print string below:

foreach my $result (@{$response->{Details}}) {
print
join "\n",
$result->{ProductName}[0]||"no title",
$result->{Asin}[0] . "\t" .
$result->{ListPrice}[0] . "\n\n";
}

You need more parentheses. Check the precedence of "||" and ".".

- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP4AG2GPeouIeTNHoEQJLJQCeOzPRuL88PDNQtICUOCTMC72ICcgAoMRN
L6yKkfLOip2AyVA8UEYhNha/
=EEIU
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top