Using grep on undefined array

Matt Freake matthew.d.freake at
Wed Aug 14 08:58:05 BST 2013

On Wed, Aug 14, 2013 at 8:40 AM, Mark Overmeer <mark at> wrote:

> * Andrew Beverley (andy at [130813 23:24]:
> > Could someone please explain to me why the following outputs an empty
> > string rather than "*"?
> @fields != @$fields, which is causing the confusion.

I don't think the original poster is confusing those two, and when I
applied 'use strict' to the original code (with the sub) it didn't help (no
warnings or errors). The bit I'm stuck on is why does

   my @fields = grep($_ ne 'domain', @$fields);

autovivify $fields but

   my @fields = @$fields;

does not.

    use strict;

    sub get()
    {   my $fields = shift;
        # my @fields = grep($_ ne 'domain', @$fields); # autovivifies
        # my @fields = @$fields; # does not autovivify fields


More information about the mailing list