Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove Duplicate - Ignore Case 2

Status
Not open for further replies.

mte0910

Programmer
Apr 20, 2005
232
0
0
US
Here is my code...how do I make it ignore case so that it will get all duplicates?


open (IN, 'P:\Directory\AFile.txt');
open (OUT,'>P:\Directory\BFile.txt');
my %hTmp;
while (my $Line5 = <IN>) {
print OUT $Line5 unless ($hTmp{$Line5}++);
}
close (IN); close (OUT);
 
Code:
[url=http://perldoc.perl.org/functions/open.html][black][b]open[/b][/black][/url] [red]([/red]IN, [red]'[/red][purple]P:\Directory\AFile.txt[/purple][red]'[/red][red])[/red][red];[/red]
[black][b]open[/b][/black] [red]([/red]OUT,[red]'[/red][purple]>P:\Directory\BFile.txt[/purple][red]'[/red][red])[/red][red];[/red]
[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]%hTmp[/blue][red];[/red]
[olive][b]while[/b][/olive] [red]([/red][black][b]my[/b][/black] [blue]$Line5[/blue] = <IN>[red])[/red] [red]{[/red]
[blue]$Line5[/blue] = [url=http://perldoc.perl.org/functions/lc.html][black][b]lc[/b][/black][/url] [blue]$Line5[/blue][red];[/red]
[url=http://perldoc.perl.org/functions/print.html][black][b]print[/b][/black][/url] OUT [blue]$Line5[/blue] [olive][b]unless[/b][/olive] [red]([/red][blue]$hTmp[/blue][red]{[/red][blue]$Line5[/blue][red]}[/red]++[red])[/red][red];[/red]
[red]}[/red]
[maroon]close[/maroon] [red]([/red]IN[red])[/red][red];[/red] [maroon]close[/maroon] [red]([/red]OUT[red])[/red][red];[/red]

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Maybe this would work better as it doesn't change the output.


Code:
open (IN, 'P:\Directory\AFile.txt');
open (OUT,'>P:\Directory\BFile.txt');
my %hTmp;
while (my $Line5 = <IN>) {
print OUT $Line5 unless ($hTmp{lc($Line5)}++);
}
close (IN); close (OUT);

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
good point....

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Thanks to you both, I will look this over Monday so that I can understand it, not just cut and paste.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top