in reply to Value of a statement with modifier

I've seen this before but it wasn't a big problem because the expression returned was false. The previous examples didn't use unless. So avoiding unless may be one way to avoid this surprise.

- tye        

Replies are listed 'Best First'.
Re^2: Value of a statement with modifier (unless)
by Jenda (Abbot) on Jan 22, 2007 at 18:38 UTC

    Well, this may actually make it even more problematic. In scalar context it's fine, but in list one you get a one element list, where the value of the element is 0, '' or undef. In either case it was something I did not expect even though I probably should so I thought it's good to post a note.

      Indeed, thanks for posting; I have now modified Perl 6 to fix this problem today--it no longer returns the last expression evaluated, but the value of the last statement in the block. Happily, fixing this (and a few other things) also makes list comprehensions a lot easier to write now.
        Indeed, thanks for posting; I have now modified Perl 6 to fix this problem today--it no longer returns the last expression evaluated, but the value of the last statement in the block. Happily, fixing this (and a few other things) also makes list comprehensions a lot easier to write now.

        How will that work with a for modifier? I've occasionally wanted

        $t += $_ for @list;

        to return the last value of $t. Okay, okay, I know in Perl 6 there will be other ways to do similar stuff, in particular functional-language like ones that will avoid the need for a temporary variable altogether, but I still wonder how this kind of situation will be handled...