in reply to Re: File comparison problem!
in thread File comparison problem!

Ok I have figured out why it is not passing the comparison. For some reason the following code is inputting one new line to many at the end of the file.
open (TEMP, ">compare") || "Cannot open compare!\n"; print TEMP $t->get("1.0", "end"); close(TEMP);
Why would this be doing that and how can I fix the issue or at least work around it?

Replies are listed 'Best First'.
Re: Re: Re: File comparison problem!
by ysth (Canon) on Dec 02, 2003 at 00:05 UTC
    Either print() is adding an extra newline (because you have the output record separator $\ set to "\n", e.g. if you are using perl's -l switch), or the extra newline is added by $t->get(), in which case you need to tell us more about what $t and get() are.
      Well $t is defined as the following:
      my $t = $mw->Scrolled("Text", -scrollbars => 'e')->pack (-side => 'bottom', -fill => 'both', -expand => 1);
      It is a scrolled text box and the get() function loads the contetnts of $t into the filehandle TEMP which is actually the file called "compare". Does this help?
      Yes it is the $t->get that is inserting the new line at the end. Is there any way to get around this? Or how could I remove the last line before comparison?
        my $filecontents = $t->get("1.0", "end"); chomp($filecontents); print TEMP $filecontents;
        or (if you want to eliminate multiple newlines, but leave at least one):
        my $filecontents = $t->get("1.0", "end"); $filecontents =~ s/\n+\z/\n/; print TEMP $filecontents;