Don't mean to be rude, but this can be done a lot simpler:
perl -ne '$s{lc $_}++ or print'
(It's actually a standard example to which I added lc, and unlike your version it prints out the line right at its first occurrance, rather than first slurping in the whole file) | [reply] [d/l] [select] |
| [reply] |
And that can be sped up even more...
perl -ne 'print if 1 == ++$s{lc $_}'
(The difference is that you don't have to create temporary variables.) | [reply] [d/l] |
Although I can't test it right now, I sincerely doubt that your version is faster, especially if you compare the optrees:
While your version does save copying the old integer value to a temporary (you realize the temporary sv is allocated at compile-time, right?), it takes two extra ops, which I'm pretty sure costs more cpu time.
And in any case the difference is too minimal (especially compared to lowercasing the string and doing a hash lookup) to justify adding to the code complexity
| [reply] [d/l] [select] |
$s{+lc}++||print
:-)
Makeshifts last the longest. | [reply] [d/l] |
| [reply] |
Why the lc? uniq as I know it is not case insensitive. You might want to note that behavior to any potential users.
| [reply] |
This discussion also took place over here where a version
is presented that takes its input on STDIN (like a typical *nix filter) as
well as in the arguments in @ARGV.
| [reply] |