CopyCodeThe Code is as follows :#! /Usr/bin/perl
#
# Use grep map to obtain the Intersection Set and supplement set of the two lists
#
Use strict;
My @ A = ("A", "B", "C", "D", "E ");
My @ B = ("B", "g", "F", "E ");
Print "list a data: @ A \ n ";
Print "List B data: @ B \ n ";
My % A = map {$ _ => 1} @;
My % B = map {$ _ => 1} @ B;
My @ C = map {$ _ => 1} @ A; #=> the operator plays the role of hash assignment.
# @ A @ B Intersection
My @ inter = grep {$ A {$ _} @ B; # intersection
Print "intersection: @ inter \ n ";
# @ A, @ B Union
My % merge = map {$ _ => 1} @ A, @ B; # Calculate the Union
My @ merge = keys (% merge );
Print "union: @ merge \ n ";
# @ A, @ B's complement set @ ca, @ CB, that is, the complement set of @ A and @ B relative to @ merge
My @ CA = grep {! $ A {$ _ }}@ merge;
My @ cb = grep {! $ B {$ _ }}@ merge;
Print "\ @ A's supplement: @ Ca \ n ";
Print "\ @ B's supplement: @ CB \ n ";