Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Do any other languages really lend themselves to the one line command tools like perl does?

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.



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.


Ruby:

   print a.join
Perl:

   print foreach @a
Ruby wins!


I think you mean:

    print @a;


Benoit Hamelin did ruby one liners - http://benoithamelin.tumblr.com/ruby1line


Agreed - one reason why I still love Perl so much, despite its obvious warts.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: