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

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.

Replies are listed 'Best First'.
Re^4: Maintaining context of the caller
by BUU (Prior) on Jul 04, 2005 at 21:54 UTC
    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.
        it is fairly clear that this particular subtlety of Perl (and Perl has a lot of them) had escaped OP

        Indeed, that's true. I included the parenthetical remark to head off any suggestions that the problem was caused by precedence. Since I had ruled that out, I obviously didn't think that was the problem, but I didn't investigate enough to find out what it was. I just assumed it was something Perl wouldn't allow. Your quoted snippet cleared up the exact reason, and I appreciate it.

      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.
        My confusion is explained and all is right with the world.