On Tue, Jan 20, 2015 at 9:12 PM, Uri Guttman <u...@stemsystems.com> wrote: > On 01/20/2015 11:28 PM, Charles DeRykus wrote: >>> >>> ... >>> or something odd >>> my $contents = do { local $/; map { chomp } <HANDLE> }; >>> >> I'm afraid this, while appealing, in my testing generates an >> incorrect result, ie, 1. >> >> <SPECULATION> >> What happens I suspect is that the map{ } is in void context, not the >> scalar context of the outer do{}. Remember parsers are not as >> all-knowing as we'd like them to be. Therefore map churns merrily >> along and tosses its intermediate results until the final line. >> Only at that point does parser wake up and say "Aha, the do{ } wants >> scalar context so my final map{} value needs >> to be returned in scalar context. So here's what map{} does in >> scalar context. From 'perldoc -f map' : > > > the map call is in scalar, not void context. the do block returns the value > of the last statement and that is being assigned to a scalar. context is > propogated in (like with subs) so map is in scalar context. regardless, > using map with no return value is never a good idea as it subverts its > purpose and misleads the reader of the code. >
Yes, I understand. I was speculating more about when the propagation occurred, i.e, early or late. By "void" context, I erred and meant that the actual map results were themselves tossed into the "void". Only the count mattered. Clearly though, the chomp occurs only on a single string anyway due to the $/ setting so it's not the intended result.. -- Charles DeRykus -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/