[33029] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4305 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 30 21:09:16 2014

Date: Thu, 30 Oct 2014 18:09:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 30 Oct 2014     Volume: 11 Number: 4305

Today's topics:
    Re: Comparing lines of strings between two files? <gravitalsun@hotmail.foo>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 31 Oct 2014 01:09:27 +0200
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: Comparing lines of strings between two files?
Message-Id: <m2ugf6$2l68$1@news.ntua.gr>

On 27/10/2014 9:40 πμ, Tuxedo wrote:
> Rainer Weikusat wrote:
>
> [...]
>
>>
>> comm -2 -3 <file #0> <file #1>
>
> As long as the files content has been sorted beforehand, comm seems to be
> the perfect utility for the purpose!
>
> Many thanks for the tip.
>
> Tuxeo
>

#   quick, and probably faulty solution









#!/usr/bin/perl;
use strict; use warnings;
my ($file_left, $file_right) = ('left.txt', 'right.txt');

open 'left',  '<', $file_left  or die "Could not read file 
\"$file_left\"  because \"$!\"\n";
open 'right', '<', $file_right or die "Could not read file 
\"$file_right\" because \"$!\"\n";

# left --> right
while (my $left = <left>)
{
chomp $left;

	while (my $right = <right>)
	{
	chomp $right;
	
		if ($left eq $right)
		{
		print "right $. == $right\n";
		last
		}
		else
		{
		print "right line $. <- $right\n"
		}
	}

last if eof 'right';
}

close 'left'; close 'right';

open 'left',  '<', $file_left  or die "Could not read file 
\"$file_left\"  because \"$!\"\n";
open 'right', '<', $file_right or die "Could not read file 
\"$file_right\" because \"$!\"\n";


# left <-- right
while (my $right = <right>)
{
chomp $right;

	while (my $left = <left>)
	{
	chomp $left;
	
		if ($left eq $right)
		{
		#print "$. == $left\n";
		last
		}
		else
		{
		print "left line $. -> $left\n"
		}
	}

last if eof 'left';
}

close 'left'; close 'right';



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 4305
***************************************


home help back first fref pref prev next nref lref last post