Is there a compelling reason why lc() and friends must return a defined value at all times? Just curious...

#!/usr/bin/perl

# defined_test.pl

use warnings;
use strict;

my %hash = (
        'one' => 'first',
        'two' => ''
);

print "test 1 is TRUE\n" if $hash{'one'};
print "test 2 is TRUE\n" if $hash{'two'};
print "test 3 is TRUE\n" if defined($hash{'two'});
print "test 4 is TRUE\n" if $hash{'three'};
print "test 5 is TRUE\n" if defined($hash{'three'});
print "test 6 is TRUE\n" if defined(lc($hash{'three'}));
print "test 7 is TRUE\n" if defined(uc($hash{'three'})) &&
                            defined(lcfirst($hash{'three'})) &&
                            defined(ucfirst($hash{'three'})) &&
                            defined(lc(my $new_var)) &&
                            defined(lc(undef())) &&
                            defined(lc());

for my $word ('one', 'two', 'three') {
        print "loop is TRUE for $word\n" if defined(lc($hash{$word}));
}

print "$_ => $hash{$_}\n" for sort keys %hash;

__END__

this is the output on 5.8.4...

test 1 is TRUE
test 3 is TRUE
test 6 is TRUE
test 7 is TRUE
loop is TRUE for one
loop is TRUE for two
loop is TRUE for three
one => first
two =>

_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to