Answer the question
In order to leave comments, you need to log in
How to do subtraction of two files in perl?
There are two files, the first has a bunch of IDs, the second has only some IDs (used). So you need to write a perl script so that it subtracts the ID of the second file from the first file. The files are very large. The first one can be up to 20k lines, so the script needs to be optimized. Help if you can =)
Answer the question
In order to leave comments, you need to log in
If I understand the question correctly.
Let's say we have two files 1.txt and 2.txt
cat 1.txt
100
2323
2390238
32322323
9002
cat 2.txt
34
4343
434
2390238
32322323
9002
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use File::Slurp;
use Array::Utils qw(:all);
my @arr1 = read_file( '1.txt', chomp => 1 );
my @arr2 = read_file( '2.txt', chomp => 1 );
# Получилось 2 массива.
# Теперь сравниваем их c помощью use Array::Utils qw(:all);
# И вычисляем разницу
# Получаем элементы из массива @аrr1, которые не входят в массив @arr2
my @minus = array_minus( @arr1, @arr2 );
for my $i (@minus){
print "$i \n";
}
100
2323
@minus
to a file, and that's all.
comm -23 file1 file2 , if you decide to write on a perl.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question