See these tests, the returned value is defined and has kind of a dual
nature:
% perl -wle 'print 2 if 0 eq ""'
% perl -wle 'print 2 if 0 == ""'
Argument "" isn't numeric in numeric eq (==) at -e line 1.
2
% perl -wle 'sub foo { 1 for @_ } print 2 if defined foo(3)'
2
% perl -wle 'sub foo { 1 for @_ } print 2 if foo(3) == 0'
2
% perl -wle 'sub foo { 1 for @_ } print 2 if foo(3) eq ""'
2
% perl -wle 'sub foo { 0 } print 2 if foo(3) eq ""'
%
Also,
~>perl -wle 'sub foo { 1 until @_ } print 2 if foo(3) eq ""'
~>perl -wle 'sub foo { 1 until @_ } print foo(3) ; print "\n"'
1
~>
Paul said:
[Disclaimer: I have no proof of anything I'm about to say. It's just
what "makes sense" to me]
Because the body of the for loop isn't the last thing the for loop
executes. Perl has to do the test condition to determine if the loop
is going to iterate again. This is much more explicit in a C-style for
loop, but no less true in a foreach-style loop.
The Until test seems to lend credibility to Paul's guess that it's
returning the result of the last compare. The documentation (perlsyn)
says "Perl's C-style for loop works like the corresponding while
loop;", on while says "The while and until modifiers have the usual
'while loop' semantics." Until is just a negated while. Logically,
what Paul said makes sense for normal while loops (it has to evaluate
the conditional to know when to break out), but as far as I can tell
there's no documented return value of a while/until/for.
I'd steer clear of relying on it unless someone can find a place in the
docs that says this is the way it's supposed to behave, but it
certainly seems to be the way that it {does} behave (for the moment,
anyway)
-- T Beck