prescott2006 has asked for the wisdom of the Perl Monks concerning the following question:
But at best the log file should not be used and probably the intermediate result should be stored in some arrays or hashes and directly be compared. But I don't know how to create different array for each of the b.txt, c.txt and d.txt automatically. Anyone can help?#!/usr/bin/perl print "Enter filename:"; chomp($fname = <STDIN>); # Open the file which contains list of files to be opened. If unsucce +ssful, print an error message and quit. open (file1,$fname) || die "Can't Open File: $fname\n"; while (<file1>) { chomp; open (file2, $_); # Open file in the list one by one $temp = $_; # Store the file name to name the corresponding +log file print "$temp\n"; # Print the file name to indicate the different +output while (<file2>) { chomp; sub grep_pattern # Print strings which contain the pattern {foreach ($_) {if (/$pattern/) { print "$1\n"; open (file3, ">>$temp.log"); print file3 "$1\n"; # Print result in log file in append m +ode close (file3); } } } $pattern = 'hello '; # Find the pattern grep_pattern; } print "\n"; # Print a blank line to seperate the results from each + file } close (file1);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Compare multiple files and output differences
by rovf (Priest) on Mar 08, 2012 at 08:45 UTC | |
|
Re: Compare multiple files and output differences
by kcott (Archbishop) on Mar 08, 2012 at 09:16 UTC | |
|
Re: Compare multiple files and output differences
by nemesdani (Friar) on Mar 08, 2012 at 08:57 UTC | |
|
Re: Compare multiple files and output differences
by JavaFan (Canon) on Mar 08, 2012 at 10:04 UTC |