in reply to Re: Maintaining context of the caller
in thread Maintaining context of the caller

Am I the only one confused by why this was quoted in reply to this node?
  • Comment on Re^2: Maintaining context of the caller

Replies are listed 'Best First'.
Re^3: Maintaining context of the caller
by GrandFather (Saint) on Jul 04, 2005 at 21:52 UTC

    From OP:

    I thought I could solve problem (2) with the following:

        wantarray ? @r : $r = &$code;
    But that gives me an error, Assignment to both a list and a scalar. (Again, before anyone asks: no, it's not a precedence problem. I even tried adding appropriate parentheses just to be sure.)

    The line of code is assignment to a conditional, but the values are not either both scalar or both list values. The Camel quote explaines that that is not an acceptable thing to do.


    Perl is Huffman encoded by design.
      The line of code is assignment to a conditional, but the values are not either both scalar or both list values. The Camel quote explaines that that is not an acceptable thing to do.
      Funny, and here I thought the error message "Assignment to both a list and a scalar" explaiend why it wasn't an acceptable thing to do.

        It does if you realise that that is what is happening in the context of a conditional. From OP's parenthetical comment it is fairly clear that this particular subtlety of Perl (and Perl has a lot of them) had escaped OP.

        I thought it worth making clear that there is no syntactic sugar that will allow OP to select a list or scalar context at run time for the call by using the conditional operator in that particular fashion.


        Perl is Huffman encoded by design.
        Funny, and here I thought the error message "Assignment to both a list and a scalar" explaiend why it wasn't an acceptable thing to do.
        No, that lets you know that it's not an acceptable thing to do. The perldiag entry explains why that's so.
Re^3: Maintaining context of the caller
by gellyfish (Monsignor) on Jul 04, 2005 at 21:49 UTC

    Yep you probably are :-) That is the perldiag entry for the error message that the OP reported. It is not permitted to assign to a conditional operator where the the second and third arguments are of different type, as the OP has here.

    /J\

    A reply falls below the community's threshold of quality. You may see it by logging in.