I am having issues with comparing 2 files using File::Compare. My problem is I open the file make no changes and compare the file to itself and it still returns a boolean 1 saying the files are different. Here is the code in question:
sub close { open (TEMP, ">compare"); print TEMP $t->get("1.0", "end"); close(TEMP); print "\$filename equals ",$filename,"\n"; if (compare($filename,"compare") == 0) { print "They are the same\n"; exit; }elsif (compare($filename,"compare") == -1) { $t->insert("end", "There was an error while comparing!\n"); }else{ print "They are different\n"; my $sw = MainWindow->new(-title=>"Content Has Changed"); my $frame = $sw->Frame->pack(-side => 'top', -fill => 'x'); $frame->Label(-text => "The file has changed since last save. Wo +uld you like to save before exiting?")-> pack(-side => 'left', -anchor => 'w'); $frame->Button(-text => "No", -background => 'navy blue', -foreg +round => 'white', -command => sub {exit;})-> pack(-side => 'right'); $frame->Button(-text => "Yes", -background => 'navy blue', -fore +ground => 'white', -command =>\&save_and_exit)-> pack(-side => 'right'); } }
The scalar "$filename" is the file that was opened in it's original form and "compare" is a temp file I create to load the changed text into from the text editor before saving. I then compare the original file to the edited file and if there have been changes I want the program to prompt to save and if there have been no changes I want the program just to save. Now as I said it prompt every time even when I am sure the files are the same. Is there an issue with "$filename" being a full file path and "compare" being a local file in this subdirectory?

In reply to File comparison problem! by Elijah

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.