#!/opt/bin/perl

$[ = 1;     # set array base to 1
$, = ' ';       # set output field separator
$\ = "\n";      # set output record separator

$FS = ';';

line: while (<>) {
    chomp;  # strip record separator
    @Fld = split(/[;\n]/, $_, 9999);
    $id = $Fld[1];
    if ($. == ($.-$FNRbase)) {
    $ids{$id} = '';
    next line;
    }
    if (!(defined $ids{$id})) {
    print "$_\n";
    }
}
continue {
    $FNRbase = $. if eof;
}

At the moment I have to run the command like that: ./1.pl file1 file2 >outputfile
Can anybody help to built in all input and output files

If you want to define the IO files in the script look into the open() function or using @ARGV to pass in parameters to use as files.

Please note, there is no urgent help here. Your question is no more important or less important then anyone elses. It will be answered by anyone that reads it when they read it and if they want to answer it.

I managed to sort the code out

use strict;

foo ('c:\1.txt', 'c:\2.txt', 'c:\3.txt');

sub foo
{
  my $file1 = shift;
  my $file2 = shift;
  my $file3 = shift;

  open F1, $file1 or die "Cannot open $file1!\n$!";
  my $exclude = join ("|", map { quotemeta( (split (/\;/, $_))[0] ) } <F1>);

  print "Searching for excludes: \n$exclude\n";

  open F2, $file2 or die "Cannot open $file2!\n$!";
  open F3, ">$file3" or die "Cannot open $file3!\n$!";
  my @tab;
  my $line = "";
  while ($line = <F2>){
   chomp($line);
   if ($line =~ /./){
    print F3 $line . ";NOK" . "\n" unless $line =~ m/$exclude/;
    }
  }
  close F1;
  close F3;
  open F1, $file1 or die "Cannot open $file2!\n$!";
  open F3, ">>$file3" or die "Cannot open $file3!\n$!";
  @tab = <F1>;
  close F1;
  print F3 @tab;
  close F3;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.