in reply to Re: "Use of uninitialized value in pattern match (m//)" warning, doing a grep on 2D array
in thread "Use of uninitialized value in pattern match (m//)" warning, doing a grep on 2D array

Thank you, you must be right, but argh I can't see them... I included elsewhere some "defined" in my script such as "if (defined($variable)..." that work fine, but here I have troubles pointing uninitialized values in my matrix. I suppressed the warning with "no warnings 'uninitialized'", but it's problematic for the other errors I could get.

I tried : my @matrix_defined = grep {defined} @matrix; with no success.

  • Comment on Re^2: "Use of uninitialized value in pattern match (m//)" warning, doing a grep on 2D array

Replies are listed 'Best First'.
Re^3: "Use of uninitialized value in pattern match (m//)" warning, doing a grep on 2D array
by hippo (Archbishop) on Oct 14, 2022 at 14:47 UTC

    Your code as presented in the OP only filters on the first column, so that's the one to use in this pre-filter - if that's the way you want to go with this.

    #!/usr/bin/env perl use strict; use warnings; use Test::More tests => 3; use Test::NoWarnings; my @matrix = ( [1, 2], [undef, 9], [3, 4] ); my $to_keep = 3; my @matrix_defined = grep { defined $_->[0] } @matrix; is $#matrix_defined, 1, '2 rows after prefilter'; my @matrix_filtered = grep { $_->[0] =~ /$to_keep/ } @matrix_defined; is $#matrix_filtered, 0, '1 row after full filter';

    🦛