in reply to Duplicate lines with spaces, tabs...

Thx, it worked! :D But I've got two more questions: 1. What does "next unless $_;" do? 2. When the file is cleaned I still get a blank line on the end of the file. How to remove that.
  • Comment on Re: Duplicate lines with spaces, tabs...

Replies are listed 'Best First'.
Re^2: Duplicate lines with spaces, tabs...
by cdarke (Prior) on Jul 17, 2008 at 13:09 UTC
    1. What does "next unless $_;" do?

    It will do the next iteration of the loop (provided the condition is still true) unless $_ is empty. Could also be written as:
    if (not $_) { next }
    An empty string, zero, or undef, are all false in Perl.
Re^2: Duplicate lines with spaces, tabs...
by jethro (Monsignor) on Jul 17, 2008 at 13:43 UTC
    When I run your code with pjotriks changes I see no blank line at the end of the result file

      Maybe you didn't copy the entire example, including the blank lines. This is my result.
      5 6 55 66
      Apparantly perlmonks.org doesn't show blank lines. But after '66' I get a new blank line.
        I used:
        $ perl -i.bak -lne 's/\A\s+//; s/\s+\Z//; next unless $_ and not $seen +{$_}++; print' input.txt
        And I didn't get empty trailing lines...
        []s, HTH, Massa
        Nvm. The problem isn't that big. I wish to thank everyone that helped me. ;)