Dr. J

I started writing this up earlier today, but I had to leave it to do some work. When I came back to post I saw that Abigail had already posted a solution. This solution may not be as fast as her's but it is cut and paste-able. If you want to use it feel free

I also tried to make it simple as possible.

Thanks,
Kristofer

#!/bin/perl -w use diagnostics; use strict; use warnings; ############################################################ sub getAllLinesFromAFileandReturnItAsAnArray($) { my ($FILE) = $_[0]; #Redundant check. This code should be unreachable just by #the way I defined this sub '($)'. I do manual checking #of each varible as an anal principle. Just my style - Kristofer if (!defined($FILE)) { die ("I did not receive a filename"); } open my $FileDescripter => $FILE or die "Could not open '$FILE'\n"; my @ListOfStringsToReturn = <$FileDescripter>; close $FileDescripter; chomp @ListOfStringsToReturn; # my @ListOfStringsToReturn = (); # open (FileDescripter, "$FILE"); # while (<FileDescripter>) # { # if (defined($_)) # { # chop; # push @ListOfStringsToReturn, $_; # } # } # close(FileDescripter); return @ListOfStringsToReturn; } #=========================================================== my $FirstFile = "FileOne.txt"; my $SecondFile = "FileThree.txt"; my @FileOne = getAllLinesFromAFileandReturnItAsAnArray($FirstFile); my @FileTwo = getAllLinesFromAFileandReturnItAsAnArray($SecondFile); for (my $i = 0; $i < @FileOne; $i++) { print "Comparing Line $i in $FirstFile ... "; my $test = undef; for (my $j = 0; $j < @FileTwo; $j++) { if ($FileOne[$i] eq $FileTwo[$j]) { print " matched to line $j in $SecondFile\n"; print " FileOne: '$FileOne[$i]'\n"; print " FileTwo: '$FileTwo[$j]'\n"; #Setting j to @FileTwo will kill this loop $j = @FileTwo; $test = 0; } } if (!defined($test)) { print " not matched. Compared to $#FileTwo entries\n"; } }
Update based on Abigail's suggestion. Thanks Abigail for the lesson in Perl.

In reply to Re: "Pattern Matching", not using regex by krisahoch
in thread "Pattern Matching", not using regex by dr_jgbn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.