Hello,

I'm a beginner to Perl and programming in general...and need some help.

I have two files, both containing a list of accounts. File 1 has one column, containing the list of accounts and File 2 has 5 columns including filename, accounts, and 3 other nonrelevant columns. I want to retrieve the accounts that're only in File2 (in other words, remove from File2 what is in File1 also)and output the filename that's associated with that account to another file. How can I do this?

Update:

Thank you for your prompt reply. I am also having troubling with the code as it's not compiling.

I have the following errors after I've made the necessary changes to the die statement...

syntax error at test.pl line 11, near "$accounts exists" syntax error at test.pl line 14, near "}"
Also, FILE_2 does not necessarilyy contain account numbers in column2, rather the columns are in the following order:
FILENAME LOC ST CO ACCOUNT
and in this case, the 3 nonrelevant columns are LOC, ST, CO...will the following line work if I make these changes to column order?
my ( $filename, @nonrelevant, $accounts ) = split( /\t/, $line );
I also didn't quite understand what's being done in this statement:
next if ( $accounts exists( @{[<FILE>]} ) );
But I need to output the FILENAME column(for accounts that exist only in FILE_2) into a third file.

Thanks!

#!/usr/bin/perl use strict; use warnings; open FILE_1, 'file1.txt' || die "ERROR:\t$!\n"; open FILE_2, 'file2.txt' || die "ERROR:\t$!\n"; while ( my $line = <FILE_2> ) { my ( $filename, $accounts, @nonrelevant ) = split( /\t/, $line ); next if ( $accounts exists( @{[<FILE>]} ) ); print "$accounts:\t$filename\n"; } close FILE_1; close FILE_2;

20051127 Edit by ysth: prepend original question


In reply to removing same entries between 2 files by sbp

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.