Jim Canon wrote:
> Hi,
>
> This is my first question, I appreciate any information you provide. I want
> to compare the numbers after : in @jn to the numbers after job in @job1 and
> @job2.
>
>
> @jn =
> JN.2007:555
> JN.2007:8433
> JN.2007:594
> JN.2007:111
> JN.2007:4663
> JN.2007.321
> JN.2007:2221
>
>
> @job1 =
> job555
> job572
> job8433
> job873
> job594
> job4663
> job2221
> job2223
>
> @job2 =
> job555
> job8433
> job873
> job594
> job4663
> job2221
> job2223
>
> I want to put what is missing in @jn compared to @job1 and @job2 in
> @jobMissing :
>
> job572
> job873
> job2223
>
> I want to put what is missing in @job1 and @job2 compared to @jn in
> @jnMissing :
> job111
> job321
Hello Jim
The program below does what you ask and produces the output
JN.2007:572
JN.2007:873
JN.2007:2223
job111
job321
Rather than work through it blow-by-blow I ask that you come back to the list
for anything you doon't understand.
HTH,
Rob
use strict;
use warnings;
my (@jn, @job1, @job2);
while (<DATA>) {
last unless /(\S+)/;
push @jn, $1;
}
while (<DATA>) {
last unless /(\S+)/;
push @job1, $1;
}
while (<DATA>) {
last unless /(\S+)/;
push @job2, $1;
}
my (%jn, %job);
@jn{map /(\d+)$/, @jn} = ();
@job{map /(\d+)$/, @job1} = ();
@job{map /(\d+)$/, @job2} = ();
my @jobMissing;
foreach my $n (sort { $a <=> $b } keys %job) {
push @jobMissing, "JN.2007:$n" unless exists $jn{$n};
}
my @jnMissing;
foreach my $n (sort { $a <=> $b } keys %jn) {
push @jnMissing, "job$n" unless exists $job{$n};
}
print "$_\n" foreach @jobMissing;
print "\n";
print "$_\n" foreach @jnMissing;
print "\n";
__DATA__
JN.2007:555
JN.2007:8433
JN.2007:594
JN.2007:111
JN.2007:4663
JN.2007.321
JN.2007:2221
job555
job572
job8433
job873
job594
job4663
job2221
job2223
job555
job8433
job873
job594
job4663
job2221
job2223
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/