Question: I have two sets of data which I need to join, but there is an added problem because the data quality is not great.

The two data sets are Calls (phone calls) and Communications (records created about phone calls). They have ID's called call\_id and comm\_id respectively. The communication records also have call\_ids to perform the join. The problem is that the data collection system was not working correctly to start with and I have a large number of communication which I cannot match to a specific call. Not all calls will have generated a communication.

For each day I need to create a joined list to perform some analysis on.
The problem is that due to the lack of some of the links I get 3 distinct row types:

* Just Calls,
* Just Comms,
* Linked comm and call.

What I want to do is for every row which is a "Just Comm" row on a given date, I should remove a "Just Call" row for the same date. I don't need any values from the calls, I just need to know the call happened. If I do this I will end up with the correct number of rows because all the "just comms" will have removed a "just call" row which as far as I need to know was the call which created the comm.

My problem is how to do this in SSIS. I have got to the point where I have my data set which contains all the data I need and is a mixture of the 3 row types I mentioned above. How would you recommend I go through the process of deleting "Just Call" rows?

Answer: 
Odd request, but this should do it:

```
#!/usr/bin/perl

use strict;
use warnings;

my $s = join '', map { "$_\n" } 1 .. 9;

my ($first) = $s =~ /^((?:.*\n){0,5})/;
my ($last) = $s =~ /((?:.*\n){0,5})$/;

print "first:\n${first}last:\n$last";

```

A more common solution would be something like this:

```
#!/usr/bn/perl

use strict;
use warnings;

#fake a file for the example    
my $s = join '', map { "$_\n" } 1 .. 9;    
open my $fh, "<", \$s
    or die "could not open in memory file: $!";

my @first;
while (my $line = <$fh>) {
    push @first, $line;
    last if $. == 5;
}

#rewind the file just in case the file has fewer than 10 lines
seek $fh, 0, 0;

my @last;
while (my $line = <$fh>) {
    push @last, $line;
    #remove the earliest line if we have to many
    shift @last if @last == 6;
}

print "first:\n", @first, "last:\n", @last;

```
Why don't you just use `head` for that?