Z
Zebee Johnstone
THis has got to be documented somewhere, but where? Couldn't find it
in learning perl - where they document what happens, but not how to get
around it, nor in perlreftut or perldsc. It's an obvious problem so
please point me where to look.
I have a hash, $hash.
If may or may not have an entry
$hash->{'fred"}
that entry if it exists, may or may not have the value 0.
How do I determine if it exists without warnings if it doesn't?
#!/usr/bin/perl -w
use strict;
use Data:
umper;
my $hash;
$hash->{'one'} = 1;
$hash->{'zero'} = 0;
for my $item (qw(one zero two)) {
if ($hash->{$item}) {
print "$item $hash->{$item}\n";
}
else {
print "$item doesn't exist\n";
}
}
v
gives
one 1
zero doesn't exist
two doesn't exist
$hash->{'zero'} does exist, but how to determine it?
If the if statement is
if (($hash->{$item}) or ($hash->{$item} == 0))
then I get warnings
one 1
zero 0
Use of uninitialized value in numeric eq (==) at z.pl line 10.
Use of uninitialized value in concatenation (.) or string at z.pl line
11.
two
is stopping warnings for just that section the only solution?
Zebee
in learning perl - where they document what happens, but not how to get
around it, nor in perlreftut or perldsc. It's an obvious problem so
please point me where to look.
I have a hash, $hash.
If may or may not have an entry
$hash->{'fred"}
that entry if it exists, may or may not have the value 0.
How do I determine if it exists without warnings if it doesn't?
#!/usr/bin/perl -w
use strict;
use Data:
my $hash;
$hash->{'one'} = 1;
$hash->{'zero'} = 0;
for my $item (qw(one zero two)) {
if ($hash->{$item}) {
print "$item $hash->{$item}\n";
}
else {
print "$item doesn't exist\n";
}
}
v
gives
one 1
zero doesn't exist
two doesn't exist
$hash->{'zero'} does exist, but how to determine it?
If the if statement is
if (($hash->{$item}) or ($hash->{$item} == 0))
then I get warnings
one 1
zero 0
Use of uninitialized value in numeric eq (==) at z.pl line 10.
Use of uninitialized value in concatenation (.) or string at z.pl line
11.
two
is stopping warnings for just that section the only solution?
Zebee