OK, I've been doing it again - trying to be a programmer. For reasons to
complicated to go into right now I've had to write a Perl program. Only
thing is it seems to be behaving in a way I wouldn't expect - here's the
output (source at end of message):
$stuff{test} is "Y" which must be "Y"
$stuff{test} is defined
$stuff{xxx} is "" which must be "Y"
$stuff{xxx} is not defined
I don't get it. I also tried
[$stuff{$name}]" != "[Y]"
and
$stuff{$name} == "Y"
(with the sense of the messages inverted). All produced the same result.
Hmmmm. I can work around that. Is there an easy way to get the number of
elements in a hash? With a normal array I can just do $#myarray - but it
doesn't work for associative arrays.
Colin
#!/usr/bin/perl
%stuff=();
sub teststuff()
{
if ($stuff{$name}!="Y") {
print "\$stuff{$name} is \"$stuff{$name}\" which is NOT same as
\"Y\"\n";
}
else {
print "\$stuff{$name} is \"$stuff{$name}\" which must be \"Y\"\n";
}
if (defined $stuff{$name} ) {
print "\$stuff{$name} is defined\n";
}
else {
print "\$stuff{$name} is not defined\n";
}
}
$name="test";
$stuff{$name}="Y";
teststuff();
$name="xxx";
# but don't assign a value in stuff
teststuff();
--------------------------------------------------------------------
http://www.lug.org.uk http://www.linuxportal.co.uk
http://www.linuxjob.co.uk http://www.linuxshop.co.uk
--------------------------------------------------------------------