On Fri, Sep 15, 2000 at 07:24:39PM -0500, David L. Nicol wrote:
> > The only decision, then, is to decide which context to use; if it
> > deparses to concatenation then it seems logical to use scalar context. 
> > This also makes sense in that you can force list context with @{[
> > $weather->temp ]} if you really wanted it.
> 
> $ perl -le 'sub w{wantarray?"WA":"WS"};print " attempt: ${\scalar(w)}"'
>  attempt: WS
> 
> Maybe we just need a shorter synonym for C<scalar>?

Or DWIM "${\foo()}" to force scalar context.  Everytime I come across that
construct I have to wonder why it's not called in scalar context.  The '$'
would seem to imply it should.

Or cause the foo() method in "foo $foo->bar bar" to be called in scalar
context by default, obviating the need for a specific scalar call.

I'd actually like both solutions to be implemented.


What's even more confusing:

    sub foo { wantarray ? "list" : "scalar" }

    print scalar("${\foo()}")       -->     "list"
    print scalar(${\foo()})         -->     "list"
    $foo = ${\foo()}; print $foo    -->     "list"

And yet:

    sub foo { wantarray ? \"list" : \"scalar" }

    print ${foo()}                  -->     "scalar"
    print ${ ("bar", foo()) }       -->     "scalar"

(These were all tested using 5.6.0.)

I have to assume \foo() is actually \(foo()) or some such.  IMHO, this is
entirely non-intuitive.  Can anyone enlighten me as to why this is as it is?
I believe there was a p5p discussion about this, but I dread delving into
the archives again..


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

Reply via email to