in reply to Re: question about || operator and list context
in thread question about || operator and list context
You see, once you actually treat an array as a container of a list, rather than treating it as a list of scalar elements, then all of a sudden it becomes clear what he was testing for. A list with two undefined elements is not an empty list; it is a list with two undefined elements. In real world examples, instead of @$_ one would be using a function call (as the OP eventually demonstrated in his other post), much like the common while(my ($k, $v) = each %hash) { } idiom. This will not abort looping on pairs such as '' => undef because that is not an empty list - it will continue running until, when each reaches the end of the hash, it receives an actual empty list.use strict; use warnings; $" = '+'; for( ['a', 'b'], [1, 2], [0, 1], ['a', 'b'], [undef, undef], [1, undef], [undef, 1], [ ], ) { print "\@\$_ is @$_\n"; (my ($foo, $bar) = @$_) || print "I would die here\n"; print "\n"; }
Makeshifts last the longest.
|
|---|