in reply to remove repeated lines with space differences
sub remove_repeated { my ($file_name) = @_; my %seen; local @ARGV = $file_name; local $^I = ".bak"; while(<>){ s/^\s+//; s/\s*$/\n/; next if $seen{$_}++; print; } }
Since you consider the leading and ending white space insignificant, I didn't see a problem with removing it. If you don't want to remove the white space from the file, copy $_, trim the copy, and use the copy as the key to the hash.
Update: I had local @ARGV = @_; originally, but I reverted it back to one file name since %seen was being incorrectly shared between all the arguments.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: remove repeated lines with space differences
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 |