>>>>> "mjd" == mjd <mjd@plover.com> writes:
mjd> What does this print?
mjd> sub foo {
mjd> my $x = 18;
mjd> bar($x);
mjd> }
mjd> sub bar { }
mjd> print foo();
mjd> Says "perlsub": "The return value of a subroutine is the value of the
mjd> last expression evaluated." It seems strange to me that this isn't
mjd> qualified with "last expression evaluated by the sub", so that
mjd> sub bar {} always returns undefined, but that if that is OK with
mjd> you, it is OK with me. Here, the last expression evaluated is the
mjd> computation of the argument $x, back in foo(), so bar() returns 18.
mjd> Now consider this:
mjd> sub foo {
mjd> my $x = 18;
mjd> $x;
mjd> bar();
mjd> }
mjd> sub bar { }
mjd> print foo();
mjd> The last expression evaluated is still $x. But bar() no longer
mjd> returns 18; instead, it returns undefined.
It's different again in 5.5.3. Both of those evaluate to undef in
scalar context, and empty list in list context, and that makes sense
to me. So perhaps something changed between 5.5.3 and the version you
are testing. I'd argue alongside you (I think) that it has become
more broken between 5.5.3 and the version you are testing.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Thread Previous