On 29/04/2011 10:27, Uri Guttman wrote:
"RD" == Rob Dixon<rob.di...@gmx.com>  writes:

   RD>  On 29/04/2011 09:15, Brian Fraser wrote:
   >>  On Fri, Apr 29, 2011 at 5:02 AM, Uri Guttman<u...@stemsystems.com>   
wrote:
   >>>
   >>>  so you can streamline yours with a slice:
   >>>
   >>>  my $status = join '', grep defined, @jvalue{ 0 .. 5 } ;
   >>
   >>  This one was on purpose though - The slice might insert new keys into the
   >>  hash, and I recently spent the good half of an hour debugging just 
that..!

   RD>  Good call Brian. It's not at all obvious that all the elements of a hash
   RD>  slice will be created if they don't exist :)

and they won't be anyhow. you need have lvalues to autovivify hash (or
array) elements.

perl -le '@x = @y{ qw( a b )}; print keys %y'

%y is empty as you can see.

I meant in the specific case of the grep that was posted. There are no lvalues there, yet they are autovivified:

  perl -le '@x = grep defined, @y{ qw( a b )}; print keys %y'

Rob

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to