![]() |
|
Perl: the Markov chain saw | |
PerlMonks |
Re^8: Unhappy returnsby Aristotle (Chancellor) |
on Oct 10, 2005 at 19:22 UTC ( #498915=note: print w/replies, xml ) | Need Help?? |
It isn't completely consistent.
I admit the value returned from the function for surprised me. It returns an honest-to-goodness false (ie. an empty string) -- not even undef. (I checked.) Interesting. Also somewhat surprising, but not nearly as much, is that the functions with while return nothing at all. Because I knew about the behaviour of if – when the condition is the last thing evaluated, it is returned, while when the body runs, its last expression's value is returned. Which is exactly as expected by the model I described. Which is exactly what perlsub describes:
I guess Perl is simply inconsistent here. Update: per Re: "last expression" quiz, I added do{} pseudo-loop tests. Update: gack, I forgot to invoke the do subs using ->. Fixed, thanks to robin in Re^4: "last expression" quiz. No wonder I got back coderefs. The actual behaviour does not seem very consistent either, though. Makeshifts last the longest.
In Section
Meditations
|
|