Hi, thanks for the help thats been given so far, im in the process of understanding the code thats been given.
heres the code i have done so far...probably not the best or most efficient code there is. It probably has a few minor bugs to get it to output where i am at so far...it starts from where i have divided the contents of the input file into approved and newly added (or unapproved), here it is.

#!/usr/bin/perl my $filename02 = "unapproved.txt"; my $filename03 = "approved.txt"; my $filename04 = "compared.txt"; open(UNAPPROVED,"+<$filename02") || die "Can't open file $filename02"; + # open destination text file open(APPROVED,"+<$filename03") || die "Can't open file $filename03"; # + open destination text file open(COMPARED,"+>$filename04") || die "Can't open file $filename04"; # + open destination text file my @unapprovedline; my @approvedline; @approvedall = <APPROVED>; @unapprovedall = <UNAPPROVED>; close APPROVED; close UNAPPROVED; $numoflines01 = @unapprovedall; $numoflines02 = @approvedall; for ($x = 0; $x < $numoflines01; $x++) { $line01 = @unapprovedall[$x]; @unapprovedline = split (/\"/, $line01); for ($y = 0; $y < $numoflines02; $y++) { $line02 = @approvedall[$y]; @approvedline = split (/\"/, $line02); $uleft = @unapprovedline[5]; $aleft = @approvedline[5]; $uright = @unapprovedline[7]; $aright = @approvedline[7]; $uping = @unapprovedline[13]; $aping = @approvedline[13]; if ($uping eq $aping && $uleft eq $aleft && $uright eq $aright +) { print COMPARED "\"", @approvedline[1], "\"", "\t"; print COMPARED "\"", @approvedline[3], "\"", "\t"; print COMPARED "\"", @approvedline[5], "\"", "\t"; print COMPARED "\"", @approvedline[7], "\"", "\t"; print COMPARED "\"", "@approvedline[9] @unapprovedline[1], +", "\"", "\t"; print COMPARED "\"", @approvedline[11], "\"", "\t"; print COMPARED "\"", @approvedline[13], "\"", "\t", "\n"; } else { print COMPARED "\"", @unapprovedline[1], "\"", "\t"; print COMPARED "\"", @unapprovedline[3], "\"", "\t"; print COMPARED "\"", @unapprovedline[5], "\"", "\t"; print COMPARED "\"", @unapprovedline[7], "\"", "\t"; print COMPARED "\"", @unapprovedline[9], "\"", "\t"; print COMPARED "\"", @unapprovedline[11], "\"", "\t"; print COMPARED "\"", @unapprovedline[13], "\"", "\t", "\n" +; } } } close COMPARED; # delete UNAPPROVED

Heres the file that is produced from the above code...

"A1000000" "" "DB50F-LEFT" "DB50F-RIGHT" "" "" + "L1:R1 L2:R2 L3:R3 L4:R4 L5:R5 L6:R6 L7:R7" "M50DFFU" "" "DB50F-LEFT" "DB50F-RIGHT" " 1000000," + "" "L1:R1 L2:R2 L3:R3 L4:R4 L5:R5 L6:R6 L7:R7" "A1000000" "" "DB50F-LEFT" "DB50F-RIGHT" "" "" + "L1:R1 L2:R2 L3:R3 L4:R4 L5:R5 L6:R6 L7:R7" "A1000000" "" "DB50F-LEFT" "DB50F-RIGHT" "" "" + "L1:R1 L2:R2 L3:R3 L4:R4 L5:R5 L6:R6 L7:R7" "A1000000" "" "DB50F-LEFT" "DB50F-RIGHT" "" "" + "L1:R1 L2:R2 L3:R3 L4:R4 L5:R5 L6:R6 L7:R7" "P000001" "" "DB9F-LEFT" "DB9F-RIGHT" " 5000001," " +" "L1:R1 L2:R2 L6:R6" "A5000001" "" "DB9F-LEFT" "DB9F-RIGHT" "" "" + "L1:R1 L2:R2 L6:R6" "A5000001" "" "DB9F-LEFT" "DB9F-RIGHT" "" "" + "L1:R1 L2:R2 L6:R6" "A5000001" "" "DB9F-LEFT" "DB9F-RIGHT" "" "" + "L1:R1 L2:R2 L6:R6" "A5000001" "" "DB9F-LEFT" "DB9F-RIGHT" "" "" + "L1:R1 L2:R2 L6:R6" "A9999999" "" "DB00F-LEFT" "DB00F-RIGHT" "" "" + "L1:R1 L3:R3 L4:R4 L6:R6" "A9999999" "" "DB00F-LEFT" "DB00F-RIGHT" "" "" + "L1:R1 L3:R3 L4:R4 L6:R6" "A9999999" "" "DB00F-LEFT" "DB00F-RIGHT" "" "" + "L1:R1 L3:R3 L4:R4 L6:R6" "A9999999" "" "DB00F-LEFT" "DB00F-RIGHT" "" "" + "L1:R1 L3:R3 L4:R4 L6:R6" "A9999999" "" "DB00F-LEFT" "DB00F-RIGHT" "" "" + "L1:R1 L3:R3 L4:R4 L6:R6"

And this is what i im trying to do with the results produced above...again this is probably a very long way of solving this problem but i cant really think of any other way to do it as my perl knowledge is limited

# for each line, get the part no., compare to contents of # the notes field on every other line, if it is in the # notes field, delete the line otherwise leave and move on # to the next line. Finally delete all dupes and merge the # list with the approved.txt open(COMPARED,"+<$filename04") || die "Can't open file $filename04"; # + open destination text file @comparedall = <COMPARED>; $numoflines03 = @comparedall; for ($a = 0; $a < $numoflines03; $a++) { $line03 = @comparedall[$a]; @comparedline = split (/\"/, $line03); $part = @comparedline[1]; $notes = @comparedline[9]; @notes = split (/\,/, $notes); $numofnotes = @notes; for ($b = 0; $b <= $numofnotes; $b++) { $notescontent = @notes[$b]; print $notescontent, "\n"; if ($part eq $notescontent) { print "hello"; } } }

Thanks for everyones help, Steve.


In reply to Re: Comparing files and and elements of arrays by Anonymous Monk
in thread Comparing files and and elements of arrays by sjd6

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.