djberg96 ([info]djberg96) wrote,
  • Mood: chipper

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.
Tags: perl, ruby

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments
Create an Account
Forgot your login or password?
Facebook Twitter More login options
English • Español • Deutsch • Русский…