I know that in s/// or m/// the /x will ignore white space ...
The /x modifier will allow you to add white space in your regular expression to make it more readable - it doesn't ignore white space in the text that you are trying to match. Example:
my $x = "foobar"; print "matches 1\n" if ($x =~ m/foo bar/x); # succeeds print "matches 2\n" if ($x =~ m/foo bar/); # fails
humm just had a thought ... how about running through the array and just removing all white space and dump into @clean, then do the same to $line just prior to the grep
This is a good idea. You are canonicalizing the input, mapping each line to a single representative so that you can just use string equality to test if the lines are "the same."

Another common perl-ish approach is to use a hash. This will avoid iterating through the the @clean array for each line in the second file:

my %hash; while (<file1>) { my $clean = ... convert $_ into its canonical form ... $hash{$clean} = 1; } while (<file2>) { my $clean = ... convert $_ into its canonical form ... if ($hash{$clean}) { # line from file2 exists in file1 } else { # line from file2 is not in file1 } }
This run time is essentially linear in the number of lines of each file.

In reply to Re: Match but ignore white space by pc88mxer
in thread Match but ignore white space by blackbeard

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.