use strict; use warnings; use Data::Dumper; my %hash=(1=>10,2=>20,3=>30,4=>40,5=>50); my $max=0; my @out=map{ $_=$hash{$_}; if($_>$max){$max=$_} # $_; }keys %hash; sub mytest { if ( 0 > 1 ) { 1; } } print "defined(mytest()) is ", defined( mytest() ) ? "defined.\n" : "undefined.\n"; print "mytest() is ", mytest() ? "true.\n" : "false.\n"; print "mytest() returns: '", mytest(), "'\n\n"; print "defined(\$out[2]) is ", defined( $out[2] ) ? "defined.\n" : "undefined\n"; print "\$out[2] is ", $out[2] ? "true.\n" : "false.\n"; print "\$out[2] returns: '", $out[2], "'\n\n"; print "defined(if(0>1){1}) is ", defined( do{ if(0>1){1} } ) ? "defined.\n" : "undefined.\n"; print "if(0>1){1} is ", do{ if(0>1){1} } ? "true.\n" : "false.\n"; print "if(0>1){1} returns: '", do{ if(0>1){1} }, "'\n\n"; print "defined(do{}) returns: ", defined( do{} ) ? "a defined value.\n\n" : "an undefined value.\n\n"; print "defined((map{if(0>1){1}}(1))[0]) is ", defined((map{if(0>1){1}}(1))[0]) ? "defined.\n" : "undefined.\n"; print "(map{if(0>1){1}}(1))[0] is ", (map{if(0>1){1}}(1))[0] ? "true.\n" : "false.\n"; print "(map{if(0>1){1}}(1))[0] returns: '", (map{if(0>1){1}}(1))[0], "'\n\n"; print "defined((map{\$_=\$hash{\$_};if(\$_>$max){\$max=\$_}}keys %hash)[2]) is ", defined((map{$_=$hash{$_};if($_>$max){$max=$_}}keys %hash)[2]) ? "defined.\n" : "undefined.\n"; print "(map{\$_=\$hash{\$_};if(\$_>\$max){\$max=\$_}}keys %hash)[2] is ", ( do{map{$_=$hash{$_};if($_>$max){$max=$_}} keys %hash} )[2] ? "true.\n" : "false.\n"; print "(map{\$_=\$hash{\$_};if(\$_>\$max){\$max=\$_}}keys %hash)[2] returns: '", (map{$_=$hash{$_};if($_>$max){$max=$_}} keys %hash)[2], "'\n\n"; #### defined(mytest()) is defined. mytest() is false. mytest() returns: '' defined($out[2]) is defined. $out[2] is false. $out[2] returns: '' defined(if(0>1){1}) is defined. if(0>1){1} is false. if(0>1){1} returns: '' defined(do{}) returns: an undefined value. defined((map{if(0>1){1}}(1))[0]) is defined. (map{if(0>1){1}}(1))[0] is false. (map{if(0>1){1}}(1))[0] returns: '' defined((map{$_=$hash{$_};if($_>50){$max=$_}}keys %hash)[2]) is defined. (map{$_=$hash{$_};if($_>$max){$max=$_}}keys %hash)[2] is false. (map{$_=$hash{$_};if($_>$max){$max=$_}}keys %hash)[2] returns: ''