in reply to map { ; ; ; } @array

Why would this be any more surprising to you than using multiple expressions (not statements as you original had used in your node) in any other block, such as an if block or a while block? :) You just have to be careful that the last expression returns what you want.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re^2: map { ; ; ; } @array
by halley (Prior) on Oct 21, 2005 at 19:07 UTC
    Considering the discussion earlier this week, the "last expression" quiz, I'd say this can get pretty interesting. If the concept of "last expression" is not well-defined, then the idiomatic usage of map can be on shaky ground as well.

    Mind you, I doubt people will write the following, but it does sound poetic to include the undefined behavior:

    my @foo = map { 1 for 1 } @bar;

    --
    [ e d @ h a l l e y . c c ]

      for is not an expression, so it shouldn't be suprising that it doesn't have a well-defined value. I think the document is a little vague, but people seem to be hung up on the sentence...
      "The return value of the subroutine is the value of the last expression evaluated."
      ...which probably should be modified to something like...
      "The return value of the subroutine is the value of the last syntatic expression."
        for is not an expression
        No, but Perl does have a construct to turn any statement into an expression, and it's called do.
        @foo = map {do {1 for 1}} @bar;
        Perl --((8:>*
Re^2: map { ; ; ; } @array
by Roy Johnson (Monsignor) on Oct 21, 2005 at 18:55 UTC
    Why do you say "not statements"? A block can certainly contain multiple statements; the last statement should be an expression, though.

    Caution: Contents may have been coded under pressure.