CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [Karazam] Search content of one file with the content of a second file: Edit Log



FishMonger
Veteran / Moderator

Mar 26, 2011, 12:38 PM


Views: 6100
Re: [Karazam] Search content of one file with the content of a second file

Since this is a homework assignment, I was trying to avoid giving away the solution, however since the "cat's out of the bag", I'll post one anyway, but I won't explain it. The OP should try to figure it out.


Code

#!/usr/bin/perl

use strict;
use warnings;

open my $rf_fh, '<', 'file1.txt' or die "failed to open file1.txt $!";
open my $rxn_fh, '<', 'file2.txt' or die "failed to open file2.txt $!";

my %seen = map { chomp; $_ => 1 } <$rf_fh>;
my @dups;
map { chomp; push @dups, $_ if exists $seen{$_} } <$rxn_fh>;

print "The following matches were found in File 1:\n\n",
join("\n", @dups);


(This post was edited by FishMonger on Mar 26, 2011, 12:38 PM)


Edit Log:
Post edited by FishMonger (Veteran) on Mar 26, 2011, 12:38 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives