Can we put this in the documentation? I.e. can we state that the user can
rely on wantarray work not only in subs (with the limitations pointed out
by Nicholas and tentatively written in my previous e-mail) but also in
"eval" and "do 'file'" calls?

Of course, if this part of the sources is likely to have variations in the
future, we should probably stick to the "sub-only" description, leaving
other scenarios as unspecified even if they work today. OTOH, if the
implementation of wantarray isn't likely to change, we could probably be
more detailed about when wantarray will work, and when not.

Of course, if the latter is the winning choice, I volunteer to write a
draft description; otherwise I'd propose the text in my previous e-mail.

Best regards,

   Flavio Poletti.


> On Tue, Jul 26, 2005 at 11:35:46PM +0200, Abigail wrote:
>> On Tue, Jul 26, 2005 at 05:37:39PM +0100, Nicholas Clark wrote:
>> >
>> > So is "wantarray's value is only specified within a subroutine or
>> method
>> > which was called directly by other perl code" true?
>>
>> No.
>>
>>     $ perl -wle 'print eval "wantarray"'
>>     1
>>     $
>>
>>
>> No subroutine, no method.
>
> A quick look at the src shows that it scans back through the current
> context stack for an eval, sub or format. From this perspective, a require
> or do "file" is an eval. If it it fails to find one, it returns undef. It
> doesn't scan previous context stacks, so it wont backtrack through magic,
> tie, overload etc.
>
> --
> The perl5 internals are a complete mess. It's like Jenga - to get the
> perl5 tower taller and do something new you select a block somewhere in
> the middle, with trepidation pull it out slowly, and then carefully
> balance it somewhere new, hoping the whole edifice won't collapse as a
> result.
>           - Nicholas Clark, based on an original by Simon Cozens.
>

Reply via email to