Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://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.
clarification
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

steven

Update:
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.

UP-Update:

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

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

Title:
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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-25 18:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found