Alden Meneses wrote:
sorry about the confusion. i should have said the file had multiple
lines besides the two listed.
i update the file once a week. it is a file with the top 100 stocks
this newspaper puts out.
so the file will have multiple lines and I guess I am really
concerned about the last two lines as that would be the most recent
one.
Guess?? Not good enough base for writing code, is it?
Anyway, to get some flexibility, I suggest that you check out the
Tie::File module. You could for instance do:
use Tie::File;
tie my @lines, 'Tie::File', $file or die "cannot bind $file $!";
my @array_b = split ' ', $lines[0];
for ( 1 .. $#lines ) {
my @array_a = @array_b;
@array_b = split ' ', $lines[$_];
compare_array( [EMAIL PROTECTED], [EMAIL PROTECTED] );
}
untie @lines;
sub compare_array {
my ($ref_a, $ref_b) = @_;
my (%seen, @bonly);
@seen{ @$ref_a } = (); # build lookup table
foreach my $item ( @$ref_b ) {
push (@bonly, $item) unless exists $seen{$item};
}
print "@bonly \n";
}
Or if you actually want to just compare the last two lines:
tie my @lines, 'Tie::File', $file or die "cannot bind $file $!";
my @array_a = split ' ', $lines[-2];
my @array_b = split ' ', $lines[-1];
compare_array( [EMAIL PROTECTED], [EMAIL PROTECTED] );
untie @lines;
HTH
--
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>