>>>>> "PS" == Peter Scott <Peter@PSDT.com> writes: >> so you have a scalar and array context being applied to @a at the same >> time. not nice. PS> I don't see why that should be a show-stopper. This is really about PS> 'propagating context', which happens, for instance, in the hook operator: PS> @c = $scalar_condition ? @a : @b; PS> And so the above can be written as PS> @a = @a ? @a : (1, 2); but we are discussing ||= and not ?: this is illegal: perl -e '@a ||= 2' Can't modify array deref in logical or assignment at -e line 1, at EOF Execution of -e aborted due to compilation errors. while this works: perl -e '@a = @a || 2 ; print "@a\n"' 2 and that is not what you want to happen in the former case (if it was legal). the definition of ||= requires the lvalue be readable as an rvalue of the same type. but assigning to @a is not the same as reading @a in a scalar context. that is the problem with arrays and ||=. it is not a problem of propogating context but that || evaluates in scalar context only. and the assignment propogates an array context. that is a contradiction so it is an illegal operation. ||= can't expand the first into the second. it is inherently a execution shortcut as well as a syntactical one. think about its origins in c, where an early compiler would generate longer code for i = i + n ; than i += n ; it was done to make the code more efficient as much as syntactic shortcuts. they knew that they could add a value to a location without reading in the location first. knowing pdp-11 assembly really helps when understanding c since many of its odd (for its time) features come from that instruction set (++,--,+=,-= *foo, etc. are all mapped directly to one pdp-11 instruction). uri -- Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books The Best Search Engine on the Net ---------- http://www.northernlight.com ==== Want to unsubscribe from Fun With Perl? Well, if you insist... ==== Send email to <fwp-request@technofile.org> with message _body_ ==== unsubscribe