On Fri, Sep 11, 2009 at 15:43, John W. Krahn <jwkr...@shaw.ca> wrote: > Chas. Owens wrote: >> >> On Fri, Sep 11, 2009 at 09:56, John W. Krahn <jwkr...@shaw.ca> wrote: >> snip >>>> >>>> You can't tell everything about the language from the docs. >>> >>> Give me an example, I'll point you to the docs. (Have you read them >>> all?) >> >> snip >> >> Okay, I will bite, where is it documented that >> >> (@a) x= 3; >> >> is an error? More generally, where is it documented that <op>= only >> works with scalar lvalues? Perl 5 does not have a specification, or >> more accurately, the source code is the specification. Without an >> external specification, there are things we know because that is just >> the they way they work (like x= not working on an array). > > OK, let's see what is happening: > > $ perl -le' > @x = "d" .. "h"; > print "1: @x"; > @x = @x x 5; > print "2: @x"; > @x = "d" .. "h"; > print "3: @x"; > @x = ( @x ) x 5; > print "4: @x"; > @x = "d" .. "h"; > print "5: @x"; > ( @x ) = @x x 5; > print "6: @x"; > @x = "d" .. "h"; > print "7: @x"; > ( @x ) = ( @x ) x 5; > print "8: @x"; > ( $d, $e, $f, $g, $h ) = "d" .. "h"; > print "9: $d $e $f $g $h"; > ( $d, $e, $f, $g, $h ) x= 5; > print "10: $d $e $f $g $h"; > ' > 1: d e f g h > 2: 55555 > 3: d e f g h > 4: d e f g h d e f g h d e f g h d e f g h d e f g h > 5: d e f g h > 6: 55555 > 7: d e f g h > 8: d e f g h d e f g h d e f g h d e f g h d e f g h > 9: d e f g h > 10: d e f g hhhhh > > > So the syntax is something like: > > VARIABLE = "STRING" x INTEGER > > OR > > LIST CONTEXT = ( LIST ) x INTEGER > > The left operand of the x operator *MUST* be a list or it will be converted > to a string. With "( @x ) x 5" the array is just copied to a list. > > So in the example: > > (@a) x= 3; > > The left operand of the x= operator can't be both an array and a list at the > same time and it won't work. snip
Ah, but it could convert the value of @a to a scalar value (the number of elements in the array) and then assign that (after repetition) to @a using list assignment. I am not saying it is useful, just that it could do it. The problem is that x= does not do list assignment and perlop makes no mention of this; however, the Camel spells it out plainly: "List assignment may be done only with the plain assignment operator...". I love perldoc, but it does not document the language nearly as well as Programming Perl. Of course, that might be why perldoc is free and Programming Perl costs roughly $50 USD (and weighs a ton). -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/