Converting from Perl to Ruby, I am trying to find an equivalent to this
Perl one-liner removing duplicate lines in a file (without sorting it at
first) :
perl -ne'$s{$_}++||print' infile >outfile
I guess uniq method could be used, but I can't find how.
On 10/5/05, Damien Wyart <damien.wyart@free.fr> wrote:
Hello,
Converting from Perl to Ruby, I am trying to find an equivalent to this
Perl one-liner removing duplicate lines in a file (without sorting it at
first) :
perl -ne'$s{$_}++||print' infile >outfile
I guess uniq method could be used, but I can't find how.
Here is a pretty close translation that does what you want:
ruby -ne 's||={};s[$_]||print;s[$_]=true'
···
--- Damien Wyart <damien.wyart@free.fr> wrote:
Hello,
Converting from Perl to Ruby, I am trying to find an
equivalent to this
Perl one-liner removing duplicate lines in a file (without
sorting it at
first) :
perl -ne'$s{$_}++||print' infile >outfile
I guess uniq method could be used, but I can't find how.
Many thanks in advance,
--
Damien Wyart
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
Converting from Perl to Ruby, I am trying to find an equivalent to this
Perl one-liner removing duplicate lines in a file (without sorting it at
first) :
perl -ne'$s{$_}++||print' infile >outfile
I guess uniq method could be used, but I can't find how.
true,
open(outfile, 'w'){|out| out << IO.readlines(infile).uniq.join}
Converting from Perl to Ruby, I am trying to find an equivalent to this
Perl one-liner removing duplicate lines in a file (without sorting it at
first) :
On 10/6/05, Damien Wyart <damien.wyart@free.fr> wrote:
Hello,
Converting from Perl to Ruby, I am trying to find an equivalent to this
Perl one-liner removing duplicate lines in a file (without sorting it at
first) :
perl -ne'$s{$_}++||print' infile >outfile
I guess uniq method could be used, but I can't find how.
Converting from Perl to Ruby, I am trying to find an equivalent to this
Perl one-liner removing duplicate lines in a file (without sorting it at
first) :
On Wednesday 05 October 2005 22:25, Ryan Leavengood wrote:
On 10/5/05, Damien Wyart <damien.wyart@free.fr> wrote:
> Hello,
>
> Converting from Perl to Ruby, I am trying to find an equivalent
> to this Perl one-liner removing duplicate lines in a file
> (without sorting it at first) :
>
> perl -ne'$s{$_}++||print' infile >outfile
>
> I guess uniq method could be used, but I can't find how.
I tried creating a version that mimics the Perl one (because Ruby
also has the -n option), but in the end this seemed easier (and
much more readable):
Maybe some Ruby golfers can shorten it some more, but since Ruby lacks
some of the more terse (and obfuscating) features of Perl, it may not
be possible.
Ryan
···
On 10/5/05, Ryan Leavengood <leavengood@gmail.com> wrote:
I tried creating a version that mimics the Perl one (because Ruby also
has the -n option), but in the end this seemed easier (and much more
readable):
On Oct 5, 2005, at 3:25 PM, Ryan Leavengood wrote:
On 10/5/05, Damien Wyart <damien.wyart@free.fr> wrote:
Hello,
Converting from Perl to Ruby, I am trying to find an equivalent to this
Perl one-liner removing duplicate lines in a file (without sorting it at
first) :
perl -ne'$s{$_}++||print' infile >outfile
I guess uniq method could be used, but I can't find how.
I tried creating a version that mimics the Perl one (because Ruby also
has the -n option), but in the end this seemed easier (and much more
readable):
Converting from Perl to Ruby, I am trying to find an equivalent to this
Perl one-liner removing duplicate lines in a file (without sorting it at
first) :
On 10/5/05, Ryan Leavengood <leavengood@gmail.com> wrote:
On 10/5/05, Damien Wyart <damien.wyart@free.fr> wrote:
> Hello,
>
> Converting from Perl to Ruby, I am trying to find an equivalent to this
> Perl one-liner removing duplicate lines in a file (without sorting it at
> first) :
>
> perl -ne'$s{$_}++||print' infile >outfile
>
> I guess uniq method could be used, but I can't find how.
I tried creating a version that mimics the Perl one (because Ruby also
has the -n option), but in the end this seemed easier (and much more
readable):
On Wednesday 05 October 2005 22:34, Ryan Leavengood wrote:
On 10/5/05, Ryan Leavengood <leavengood@gmail.com> wrote:
> I tried creating a version that mimics the Perl one (because Ruby
> also has the -n option), but in the end this seemed easier (and
> much more readable):
>
> ruby -e "puts IO.readlines(ARGV[0]).uniq" infile > outfile
>
> So you are right about using uniq.
Just for sake of comparison, here is the more "Perl-like" version:
Maybe some Ruby golfers can shorten it some more, but since Ruby
lacks some of the more terse (and obfuscating) features of Perl, it
may not be possible.