[Solved] Comparing two files in perl [closed]


the code maybe looks like this:

#!/usr/bin/perl

use strict;
use warnings;

my @array = ('1','2','3','5','6');
my @array2 = ('1', '3', '7', '6');

for my $item(@array2)
{
    if (grep($_ == $item, @array) > 0)
    {
         print "$item, Match\n";
    }
    else
    {
        print "$item, Not Match\n";
    }
}

Output

1, Match
3, Match
7, Not Match
6, Match

PS: reference from a comment by @simbabque

The @ sigil tells Perl that a variable is an array. The () is the list constructor, and in list context the list will be assigned to the array. [] constructs an array reference, which in list context will be treated as a one-element list and thus if you assign that to an array, you will end up with a one element array like @foo = ( [ 1, 2, 3 ] ). The OP is using {}, which constructs a hash reference, and works the same way, but since one of the two has an uneven number of elements, it will error out.

4

solved Comparing two files in perl [closed]