I am trying to write code that confirms every row in 2 dimensional array has all unique values.
@x2 = uniq( @q2 ); produced array with 10 elements instead of 6; then $y2 = @x2; produced 1??
I don't understand why x2 is different than x1 and y2 is different than y1? I am expecting x2 with 5 elements and y2=5 (just like y1). How can I fix this?
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use List::MoreUtils qw(uniq);
my @q1 = (6,0,0,5,0,7,0,0,1,0);
my @x1 = uniq( @q1 );
my $y1 = @x1;
print "y1 = ",Dumper( $y1 );
print "x1 = ",Dumper( @x1 );
print "q1 = ",Dumper( @q1 );
print '====='."\n";
my @b = ();
push @{ $b[0] }, (0,8,0,0,0,9,3,5,6,7);
push @{ $b[1] }, (6,0,0,5,0,7,0,0,1,0);
my $r=1;
my @q2=$b[$r];
my @x2 = uniq( @q2 );
my $y2 = @x2;
print "y2 = ",Dumper( $y2 );
print "x2 = ",Dumper( @x2 );
print "q2 = ",Dumper( @q2 );
print "b[r]=",Dumper( $b[$r] );
@q2in the shown code doesn't have 10 elements (?) -- you assign$b[1]to it, an array reference so a single scalar. So@x2has the same, one element which is an array reference. Do as @Сухой27 says instead,@{$b[$r]}.= ()) to a newly-created array (my @b). It's already empty.