| djberg96 ( @ 2006-05-26 14:51:00 |
| Current mood: | |
| Entry tags: | perl, ruby |
I like Ruby
Today merlyn (Randal Schwartz) posted this tidbit. Here it is in Ruby:
File.open('pidfile', 'w+'){ |fh| fh.print Process.pid }
Shorter, yet clearer - and that's the long version! I could have used '$$' instead of Process.pid, but I prefer readability. Even if you don't know Ruby you can still read this. I doubt you could say the same for Perl.
Yes, I like Ruby.
Update: As dagbrown pointed out on IRC, the Perl version leaks handles and uses Perl's autoflush feature. I also updated the code slightly to use print instead of puts, since you probably don't want a newline there.