Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hello All, I am trying to compare two files, and send the difference to another file. I have usernames in the first, and if they don't match the second, i want to print/redirect that username to the third file. So far, I have some pseudo-code. My conflict lies in plain noobness. I am getting really bent on filehandles and arrays/hashes.
Essentially, I would like the iterpreter to read the first line of FILE1, if its paattern is matched on FILE2, continue to Line 2 of FILE1, and repeat check on FILE2.. Else, print to screen, or to another file. Here is what I have so far:
#!/usr/bin/perl -w use strict; open(FIRST,"first.txt") || die "$!"; @first = <FIRST>; close FIRST; open(LAST,"last.txt") || die "$!"; @last = <LAST>; close LAST; foreach $i (@first){ if ($i =~ m/@last) }else{ print "$_"; }

Thanks in advance for any help


no, this isn't homework :), a colleague and I are trying to match our userbase with the ones we've downloaded from our spam filter provider. we're trying to match/compare/contrast our username list with theirs (then we can batch upload our unfiltered and angry users' names). the file itself is under 1MB (about 40,000 lines). Diff doesn't work because they don't line up exactly, and grep -v -f etc.. choked on us as well. Perl seemed like my last straw.


The code below satisfies my requirements for what I have to do. THANKS all!!!

In reply to matching the contents of two (2) files by stevenrh

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2023-12-02 04:57 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (13 votes). Check out past polls.