in reply to Matching arrays

You can match arrays by copying them in a string and then matching the strings as follows.
my $Line1 = join(" ",@array1); my $Line2 = join(" ",@array2); if ($Line1 =~ /$Line2/) { $Match = 1; } else { $Match = 0; }

Edit by tye, add CODE tags

Replies are listed 'Best First'.
Re: Re: Matching arrays
by Anonymous Monk on Mar 26, 2003 at 08:03 UTC
    above code won't work if the elements in array are not in order. solution is here:
    my $Line1 = join(" ",@a1); my $Match = 0; for ($i=0;$i<=$#a2;$i++) { if ($Line1 =~ /$a2[$i]/) { $Match = 1; } else { $Match = 0; print " No match"; last; } } if ($Match == 1) { print " Match"; }

    Edit by tye, add CODE tags