in reply to Re: Match operator giving unexpected output
in thread Match operator giving unexpected output

>  when scalar is applied to a list,

Here "list" is to be read as comma separated (literal) list. (see scalar comma separator)

Sorry for nitpicking but there is too much confusion. ..

Cheers Rolf

PS: Je suis Charlie!

  • Comment on Re^2: Match operator giving unexpected output

Replies are listed 'Best First'.
Re^3: Match operator giving unexpected output
by Anonymous Monk on Jan 13, 2015 at 11:53 UTC
    LanX> when scalar is applied to a list,

    Here "list" is to be read as comma separated (literal) list. (see scalar comma separator)

    Sorry for nitpicking but there is too much confusion. .

    What confusion where (where is the confusion)? And how is this distinction important? In this case?

    I think its unimportant , esp in this case, a distinction without a difference ... list literal or literal list is not even in perlglossary

    A different demo of the "null list"

    ## a literal list in list context $ perl -le " print( qw/ a b c d / )" abcd ## a literal list in scalar context $ perl -le " print( scalar qw/ a b c d / )" d ## a literal list in lvalue list context ## a literal list in list context ( the left hand side list also hap +pens to be an lvalue) ## a literal list in list assignment (list context ) $ perl -le " print( ( $q ) = qw/ a b c d / )" a ## null list in scalar context counts, counting a list literal $ perl -le " print( $q = () = qw/ a b c d / )" 4 ## null list in scalar context counts, counting a "list" $ perl -le " @f = qw/ a b c d /; print( $q = () = @f )" 4 ## null list in scalar context counts $ perl -le " print( scalar( () = qw/ a b c d / ) )" 4 ## null list in list context discards (using literal list) $ perl -le " print( () = qw/ a b c d / )" ## null list in list context discards (the array kind of list ) $ perl -le " @f = qw/ a b c d /; print( () = @f )"
      > What confusion where (where is the confusion)?

      in the following you (could) see a flattened "list", but scalar doesn't return the last element, which should be 5.

      DB<118> @a=(4,5) => (4, 5) DB<119> scalar (1,2,3,@a) => 2

      in reality there is only the scalar comma operator returning the scalar of the last expression, which is here the size of @a.

      Cheers Rolf

      PS: Je suis Charlie!

        LanX I think you just found a perl bug
        $ perl -e"@f=4..5;print scalar( 1,2,3,@f) " 2 $ perl -e"@f=4..5;print scalar( 1,2,3,) " 3