I am trying to run array_diff on 2 arrays.
sub array_diff(\@\@) {
my %e = map { $_ => undef } @{$_[1]};
return @{[
( grep { (exists $e{$_}) ? ( delete $e{$_} ) : ( 1 ) } @{ $_[0] } ),
keys %e
] };
}
my $col = 'col';
my $stg = 'stg';
my @blocks = qw( block1 block2 block3 block4 block5 );
my %hash; @{$hash{$col}{$stg}} = qw( block1 block2 block3 );
my @diff = array_diff(@all_blocks, @{$hash{$col}{$stg}});
print ("diff : @diff\n");
It gives me the following error when above line is executed:
Possible unintended interpolation of @diff in string at get_blocks.pl line 56.
Type of arg 2 to main::array_diff must be array (not reference constructor) at get_blocks.pl line 55, near "})"
syntax error at get_blocks.pl line 55, near "})"
Execution of get_blocks.pl aborted due to compilation errors.
However when I try the same without an array of hash it works
my @a = qw( a b c d e);
my @b = qw( c d );
sub array_diff(\@\@) {
my %e = map { $_ => undef } @{$_[1]};
return @{[
( grep { (exists $e{$_}) ? ( delete $e{$_} ) : ( 1 ) } @{ $_[0] } ),
keys %e
] };
}
# symmetric difference
my @diff = array_diff(@a, @b);
print ("diff : @diff\n");
Result:
diff : a b e