Shit like this is why Perl gets under my skin. The best way to do anything in Perl always seems to be some side effect of a clever hack, instead of actually solving the damn problem expressively.
The equivalent in Ruby?
gem list $GEMNAME
It's shorter and more clear. Take that, Perl golfers!
Compared to Ruby, one liners are more efficient in Perl because the normally infuriating cryptic variables and defaults save space. For example in Perl you can run a foreach without naming the current iteration value and it defaults to $_. $_ in turn is the default target for many commands, like print.
So Perl's `print foreach @a` becomes Ruby's `a.each{|a| print a}`. Not so bad but it adds up.
It isn't exactly the same--some examples are two or three lines and it's more about coolness than practicality--but it's in a similar spirit, and, more importantly, also interesting.
OK, thats not really clear from the layout. Your example is clearer, but if you have to put it in a script and pipe stuff to it, its not really a 1-liner.
26 comments
[ 3.3 ms ] story [ 62.7 ms ] threadThe equivalent in Ruby?
It's shorter and more clear. Take that, Perl golfers!The only one off the top of my head would be ruby but I don't have that much ruby knowledge to judge.
This kind of thing however is perl's bread and butter.
So Perl's `print foreach @a` becomes Ruby's `a.each{|a| print a}`. Not so bad but it adds up.
It isn't exactly the same--some examples are two or three lines and it's more about coolness than practicality--but it's in a similar spirit, and, more importantly, also interesting.
-- split at whitespace -- "hello world" -> ["hello","world"] words
Not really in the same spirit at all.