in reply to local & global function
use strict; use warnings; my ($test,$test2,$test3); # parens needed for my(LIST) print "$test\n"; ## print nothing if(not defined $test){ $test3 = "GOOD"; # no my, no private but upper scope print "$test3\n" } ## print GOOD print "$test\n"; ## print nothing if (not defined $test2) { print "$test3\n"; # print $test3 from upper scope } ## print GOOD. GOOD is defined on first "if" function.
RESULT:
it's generally a bad idea to print undefined values. I suppose it's a test so I left the warnings in.Use of uninitialized value $test in concatenation (.) or string at d:/ +tmp/pm/my.pl line 8. Use of uninitialized value $test in concatenation (.) or string at d:/ +tmp/pm/my.pl line 15. GOOD GOOD
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice
|
|---|