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
    I'd also suggest
    s/\s+/ /g;

    print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."
      He said he wanted to ignore differences in leading and trailing white space. I didn't include that because that would move differences in internal white space.

        Thanks!
        Your worked worked just the way i wanted...
        sadly im wondering why i couldnt think of this simple solution?! :(