3 ms·
I made a compilation of Ruby one-liners [1] as well last year. There's plenty of stuff that is similar to Perl, which in turn had borrowed from awk, sed and ot
by asicsp 7y ago
I made a compilation of Ruby one-liners [1] as well last year.
There's plenty of stuff that is similar to Perl, which in turn had borrowed from awk, sed and other tools. The biggest difference I'd pick is Perl's context based operation.
# Ruby requires explicit conversion with to_i
ruby -ane 'print if $F[1].to_i > 35'
perl -ane 'print if $F[1] > 35'
Performance is slower compared to Perl, but to those who already know Ruby, this would suit better than learning the nuances of another language.
[1] https://github.com/learnbyexample/Command-line-text-processing/blob/master/ruby_one_liners.md https://github.com/learnbyexample/Command-line-text-processi...
- Maledictus 7y agoI can't stand weak types, so I prefer Ruby even if it is a little longer. Thanks for pointing this out.
- pizza234 7y agoThere are other significant other functionalities that I find very handy in oneliners, notably: - automatic associative array instantiation - the return value of regular expressions with a capture group is the value matched by it (in Ruby, the closest to this is `[/regex/, <group_i>]`)