in reply to map() and grep() suppress "Can't use an undefined value as an ARRAY reference at ..." errors

I translated your map{} into the equivalent foreach() statement.
All map statements have an equivalent for() or foreach() loop.
use strict; use warnings; use Data::Dumper; my $this_key = "NOT_IN_HASH"; my $hash_ref = {}; my @items; @items = map { $_->{value} } @{$hash_ref->{$this_key}}; print Dumper \@items; my @x; foreach (@{$hash_ref->{$this_key}}) # loop does not execute # because array is empty { print "loop is looping\n"; #This doesn't ever print ! push @x, $_->{value}; } print Dumper \@x; my @nothing; print Dumper \@nothing; __END__ Prints: $VAR1 = []; #print Dumper \@items; $VAR1 = []; #print Dumper \@x; $VAR1 = []; #print Dumper \@nothing;
  • Comment on Re: map() and grep() suppress "Can't use an undefined value as an ARRAY reference at ..." errors
  • Download Code