hi,
I have a question regarding how to compare 2 different C source files(e.g. Text1.c, stub.c), which contain names of function calls.

My objective is to compare these 2 source file and get rid of any occurances of the function names inside Text1.c(reference file) from stub.c(working file)

The problem I have is that my code doesn't seem to be able do that. The script seems to just copy the all same function calls that I have in stub.c, without removing any occurance of the repeated function calls found in Text1.c

#!/user/bin/perl -w #note: %hash1 contains modified functions, #which has been extracted from a C source file(Test1.c). #this hash is used for referencing purposes @array = %hash1; #initiate a loop counter $loop = 0; #using for loop to get rid of new line in the array for (@array){ $array[$loop] =~ s/\n//; $loop++ } #opening file for writing open (Done, ">sim.c") or die "Can't open sim.c :$!\n"; #initiating a new hash and a string for later use %hash2; $done; #a for loop to help popping all the elements in array. for (0..6){ $fish = pop @array; $fish = pop @array; #opening of working file, which is to be compared with #the reference array(%hash1) open (Local, "stub.c") or die "Can't open stub.c :$!\n"; for $local(<Local>){ $local =~ s/\n//; #this is used to compare the 2 variable #if there is no match, assign it as a key to a hash unless ($fish eq $local){ $hash2{$local}++; } close Local; } } #print each key of the hash to verify result foreach $done ( keys %hash2){ print "$done\n"; }

Note to monk pg and monk etcshadow: I am the idiot who posted the previous thread under Anonymous Monk. A thousand apologies to monk pg and monk etcshadow. I should have posted the full code


In reply to Comparing 2 C files by Anonymous Monk
in thread Comparing files by Anonymous Monk

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.