joeperl has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
Im using the below code to remove repeated lines in my file.
sub remove_repeated(){ my %seen(); local @ARGV = ($file_name); local $^I = ".bak"; while(<>){ %seen {$_}++; next if $seen{$_}>1; print; } }
The problem is that if my input file has 2 lines with just a difference of a white space at the beginning or end, then those 2 lines are considered unique by the above code. How to change it so as to neglect white space characters?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: remove repeated lines with space differences
by ikegami (Patriarch) on Feb 16, 2010 at 06:46 UTC | |
by Utilitarian (Vicar) on Feb 16, 2010 at 10:59 UTC | |
by ikegami (Patriarch) on Feb 16, 2010 at 15:47 UTC | |
by joeperl (Acolyte) on Feb 18, 2010 at 06:05 UTC |