<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Duplications remover.' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Duplications remover.' posted on the 'Perl' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2012 Programmers Heaven</copyright>
    <pubDate>Wed, 23 May 2012 23:02:06 -0700</pubDate>
    <lastBuildDate>Wed, 23 May 2012 23:02:06 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Duplications remover.</title>
      <link>http://www.programmersheaven.com/mb/perl/416493/416493/duplications-remover/</link>
      <description>Hey all.&lt;br /&gt;
Okay I am kind of new to PERL.&lt;br /&gt;
&lt;br /&gt;
I have 2 files A.txt and B.txt now I compare A.txt to B.txt and if file B.txt doesn’t have the word in it that file A.txt has, file B.txt gets updated with the new word from file A.txt&lt;br /&gt;
&lt;br /&gt;
This is the problem that I have, file A.txt has the word AAAS duplicated a number of times and file B.txt does not have the word in it.&lt;br /&gt;
The first time around B.txt gets updated with the new word AAAS and then when A.txt compares AAAS in B.txt, B.txt gets updated again with the word AAAS. &lt;br /&gt;
Duplicating the word AAAS in file B.txt as well.&lt;br /&gt;
&lt;br /&gt;
How do I stop this from happening??&lt;br /&gt;
&lt;br /&gt;
Following is the code that i am using. . . &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
my($comepare_word);
my($compare_dic_word);
my($flag) = "false";

sub trim($)
{
	my $string = $_;
	$string =~ s/^\s+//;
	$string =~ s/\s+$//;
	return $string;
}

open compareWord, "&amp;lt;A.txt" or die "Main file cannot be opend $!";

	while(&amp;lt;compareWord&amp;gt;) {
 		chomp;
 		$comepare_word = trim($_);

		$first_char = substr($comepare_word, 0, 1);

 		if ($first_char eq "a" || $first_char eq "A" ) {
			open compareDic, "&amp;lt;B.txt" or die "B.txt cannot be opend $!";
			while(&amp;lt;compareDic&amp;gt;) {
					chomp;
  					$compare_dic_word = trim($_);
					if($comepare_word eq $compare_dic_word) {
						$flag = "true";						
						last;
					} else {
						$flag = "false";
					}		
		}

		if($flag eq "false"){
			open outFile, "&amp;gt;&amp;gt;B.txt" or die "OUT cannot be opend $!";			
			print outFile "$comepare_word\n";
			$flag = "false"; 			
 	 	}
	}
}
&lt;/pre&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/perl/416493/416493/duplications-remover/</guid>
      <pubDate>Sun, 16 May 2010 10:40:24 -0700</pubDate>
      <category>Perl</category>
    </item>
    <item>
      <title>This post has been deleted.</title>
      <link>http://www.programmersheaven.com/mb/perl/416493/416908/this-post-has-been-deleted/#416908</link>
      <description>This post has been deleted.</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/perl/416493/416908/this-post-has-been-deleted/#416908</guid>
      <pubDate>Mon, 31 May 2010 23:46:21 -0700</pubDate>
      <category>Perl</category>
    </item>
  </channel>
</rss>
