目前自己编写和网上查阅到比较方便的三种方法。
目录
1. 代码如下:
#! /usr/bin/perl
use warnings;
use strict;
open A, $ARGV[0] or die;
open B, $ARGV[1] or die;
open UNION, '>', "union.txt" or die;
open INTSEC, '>', "intsec.txt" or die;
open DIFF, '>', "diff.txt" or die;
open A_SPEC, '>', "a_spec.txt" or die;
open B_SPEC, '>', "b_spec.txt" or die;
my @a;
my @b;
while (<A>) {
chomp;
push @a, $_;
}
while (<B>) {
chomp;
push @b, $_;
}
my @union;#并集
my @diff; #差集
my @intsec;#交集
my @a_spec;
my @b_spec;
my %union;
my %intsec;
my %a;
my %b;
foreach (@a) {$union{$_}++; $a{$_}++;}
foreach (@b) {$union{$_}++; $b{$_}++;}
@union = keys %union;
foreach (@union) {
if (exists $a{$_} and $union{$_} == 1) {
push @a_spe