in reply to local & global function
You want the same variable to hold two different values in the same scope. That won't work.
Unless you do something weird like use dualvar and evaluate in number or string context to force one or another value to be used.
... but really it seems like you need to rethink your program design. Can you share the big picture of what you are trying to do?use strict; use warnings; no warnings 'uninitialized'; ## not recommended use Scalar::Util 'dualvar'; my ($test, $test2); print sprintf('1: %s', $test), "\n"; if (not defined $test) { $test = dualvar(0, 'OK'); print sprintf('2: %s', $test), "\n"; } print sprintf('3: %s', $test > 1 ? $test : undef), "\n"; if (not defined $test2) { print sprintf('4: %s', $test), "\n"; } __END__
Hope this helps!
|
|---|