Alden Meneses wrote:
here is my updated code but it is not my loops are not set correctly
as I get nothing when i print to screen.....
open(IBDINA, "<$file") || die "cannot open $file $!";
open(IBDINB, "<$file") || die "cannot open $file $!";
chomp(@list_a=<IBDINA>);
chomp(@list_b=<IBDINB>);
for ($a = 0; $a < @list_a; $a+=2){
@array_a=(split(/ /,$list_a[$a]));
for ($b =1; $b < @list_b; $b+=2){
@array_b=(split(/ /,$list_b[$b]));
@[EMAIL PROTECTED] = (); # build lookup table
foreach $item ($array_b){
push(@bonly, $item) unless exists $seen{$item};
print @bonly;
}
}
}
close(IBDINA);
close(IBDINB);
Sorry to say it, but it looks terrible. ;-)
First and foremost, you are not using strictures and warnings. Posting
non-working code to a mailing list, without having had Perl perform some
basic checks, is bad, bad, bad.
Another thing is that you open two filehandles to the same file, and
unnecessarily complicates the assigning of the arrays. There is no need
for those outer loops.
This is a simplification of your code:
#!/usr/bin/perl
use strict;
use warnings;
my $file = '/path/to/file';
open IBDIN, "< $file" or die "cannot open $file $!";
my @array_a = split ' ', <IBDIN>;
my @array_b = split ' ', <IBDIN>;
close IBDIN;
my (%seen, @bonly);
@[EMAIL PROTECTED] = (); # build lookup table
foreach my $item ($array_b){
push(@bonly, $item) unless exists $seen{$item};
print @bonly;
}
__END__
Now, that code is not correct either. Actually, it doesn't even compile
since strictures are enabled, but just that fact illustrates how using
strict can help you detect a mistake.
Hopefully the above will help you move forward, and concentrate on the
comparison part of your program.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>