Using grep on undefined array

Adrian Lai perl at
Wed Aug 14 14:30:47 BST 2013

On 14 August 2013 13:12, Abigail <abigail at> wrote:

> My guess: it's an unintentional side-effect of $_ being an alias in the
> first argument of grep.

That does appear to be the case, given as other functions don't autovivify.
e.g.  perl -E '$y = scalar @$x; say "$x" if defined $x'

Interestingly though, 'keys' does: perl -E '@y = keys %$x; say "$x" if
defined $x'
I'm guessing that perl attempts to coerce a hash (and thus autovivify)
before it performs the keys action.


More information about the mailing list